1// RUN: %check_clang_tidy %s misc-misleading-bidirectional %t
2
3void func(void) {
4 int admin = 0;
5 /*‮ }⁦if(admin)⁩ ⁦ begin*/
6 // CHECK-MESSAGES: :[[#@LINE-1]]:3: warning: comment contains misleading bidirectional Unicode characters [misc-misleading-bidirectional]
7 const char msg[] = "‮⁦if(admin)⁩ ⁦tes";
8 // CHECK-MESSAGES: :[[#@LINE-1]]:22: warning: string literal contains misleading bidirectional Unicode characters [misc-misleading-bidirectional]
9}
10
11void all_fine(void) {
12 char valid[] = "some‮valid‬sequence";
13 /* EOL ends bidi‮ sequence
14 * end it's fine to do so.
15 * EOL ends ⁧isolate too
16 */
17}
18
19int invalid_utf_8(void) {
20 bool isAdmin = false;
21
22 // the comment below contains an invalid utf8 character, but should still be
23 // processed.
24
25 // CHECK-MESSAGES: :[[#@LINE+1]]:3: warning: comment contains misleading bidirectional Unicode characters [misc-misleading-bidirectional]
26 /*€‮ } ⁦if (isAdmin)⁩ ⁦ begin admins only */
27 return 1;
28 /* end admins only ‮ { ⁦*/
29 // CHECK-MESSAGES: :[[#@LINE-1]]:3: warning: comment contains misleading bidirectional Unicode characters [misc-misleading-bidirectional]
30 return 0;
31}
32
33// CHECK-MESSAGES: :[[#@LINE+1]]:19: warning: string literal contains misleading bidirectional Unicode characters [misc-misleading-bidirectional]
34char invalid1[] = "‮⁦‬⁩";
35
36// Test that segment and paragraph separator correctly reset the state
37char valid1[] = R"||(‮
38‮‮ ‮)||";
39
40

source code of clang-tools-extra/test/clang-tidy/checkers/misc/misleading-bidirectional.cpp