Skip to content

Commit bb28522

Browse files
mborlanddaveedvdv-nvidia
authored andcommitted
Recognize an attribute namespace only on an exact name match. [GH edgcpp#305]
1 parent 4047642 commit bb28522

7 files changed

Lines changed: 146 additions & 1 deletion

File tree

‎src/attribute.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,7 @@ namespace. If non-zero, length represents the number of characters in name
10961096
length = strlen(name);
10971097
} /* if */
10981098
for (np = valid_attribute_namespaces; *np != NULL; np++) {
1099-
if (strncmp(*np, name, length) == 0) {
1099+
if (strncmp(*np, name, length) == 0 && (*np)[length] == '\0') {
11001100
result = TRUE;
11011101
break;
11021102
} /* if */
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[GH #305]
2+
Attribute namespaces that only start like a known one are not recognized
3+
4+
An attribute namespace was treated as known if it was merely the first part
5+
of the name of a known namespace; the whole name must now match.
6+
For example:
7+
8+
[[cl::x]] int a; // Warning: attribute namespace "cl" is unrecognized
9+
[[g::y]] int b; // Previously, the namespace was accepted.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
fe_only -DTEST_NUMBER=1 --c++17 Test_name.c
2+
"Test_name.c", line 19: warning: attribute namespace "cl" is unrecognized
3+
[[cl::x]] int a;
4+
^
5+
6+
"Test_name.c", line 20: warning: attribute namespace "gn" is unrecognized
7+
[[gn::y]] int b;
8+
^
9+
10+
"Test_name.c", line 21: warning: attribute namespace "g" is unrecognized
11+
[[g::z]] int c;
12+
^
13+
14+
"Test_name.c", line 22: warning: attribute namespace "ms" is unrecognized
15+
[[ms::w]] int d;
16+
^
17+
18+
"Test_name.c", line 23: warning: attribute namespace "_Cl" is unrecognized
19+
[[_Cl::v]] int e;
20+
^
21+
22+
"Test_name.c", line 25: warning: unknown attribute "gnu::x"
23+
[[gnu::x]] int f;
24+
^
25+
26+
"Test_name.c", line 26: warning: unknown attribute "__gnu__::x"
27+
[[__gnu__::x]] int g;
28+
^
29+
30+
"Test_name.c", line 27: warning: unknown attribute "clang::x"
31+
[[clang::x]] int h;
32+
^
33+
34+
"Test_name.c", line 28: warning: unknown attribute "msvc::x"
35+
[[msvc::x]] int i;
36+
^
37+
38+
"Test_name.c", line 29: warning: unknown attribute "_Clang::x"
39+
[[_Clang::x]] int j;
40+
^
41+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Matches for "attribute namespace "cl" is unrecognized":
2+
<-----------------------------------------------------------------------------
3+
attribute namespace "cl" is unrecognized
4+
----------------------------------------------------------------------------->
5+
Matches for "attribute namespace "gn" is unrecognized":
6+
<-----------------------------------------------------------------------------
7+
attribute namespace "gn" is unrecognized
8+
----------------------------------------------------------------------------->
9+
Matches for "attribute namespace "g" is unrecognized":
10+
<-----------------------------------------------------------------------------
11+
attribute namespace "g" is unrecognized
12+
----------------------------------------------------------------------------->
13+
Matches for "attribute namespace "ms" is unrecognized":
14+
<-----------------------------------------------------------------------------
15+
attribute namespace "ms" is unrecognized
16+
----------------------------------------------------------------------------->
17+
Matches for "attribute namespace "_Cl" is unrecognized":
18+
<-----------------------------------------------------------------------------
19+
attribute namespace "_Cl" is unrecognized
20+
----------------------------------------------------------------------------->
21+
Matches for "\A(?![\s\S]*attribute namespace "(gnu|__gnu__|clang|_Clang|msvc)" is unrecognized)":
22+
<-----------------------------------------------------------------------------
23+
24+
----------------------------------------------------------------------------->
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
fe_only -DTEST_NUMBER=1 --c++17 Test_name.c
2+
"Test_name.c", line 19: warning: attribute namespace "cl" is unrecognized
3+
[[cl::x]] int a;
4+
^
5+
6+
"Test_name.c", line 20: warning: attribute namespace "gn" is unrecognized
7+
[[gn::y]] int b;
8+
^
9+
10+
"Test_name.c", line 21: warning: attribute namespace "g" is unrecognized
11+
[[g::z]] int c;
12+
^
13+
14+
"Test_name.c", line 22: warning: attribute namespace "ms" is unrecognized
15+
[[ms::w]] int d;
16+
^
17+
18+
"Test_name.c", line 23: warning: attribute namespace "_Cl" is unrecognized
19+
[[_Cl::v]] int e;
20+
^
21+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
fe_only -DTEST_NUMBER=1 --c++17 Test_name.c
2+
"Test_name.c", line 19: warning: attribute namespace "cl" is unrecognized
3+
[[cl::x]] int a;
4+
^
5+
6+
"Test_name.c", line 20: warning: attribute namespace "gn" is unrecognized
7+
[[gn::y]] int b;
8+
^
9+
10+
"Test_name.c", line 21: warning: attribute namespace "g" is unrecognized
11+
[[g::z]] int c;
12+
^
13+
14+
"Test_name.c", line 22: warning: attribute namespace "ms" is unrecognized
15+
[[ms::w]] int d;
16+
^
17+
18+
"Test_name.c", line 23: warning: attribute namespace "_Cl" is unrecognized
19+
[[_Cl::v]] int e;
20+
^
21+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//type:fp
2+
//options:--c++17
3+
//remark:[GH #305] Attribute namespaces that only start like a known one
4+
//match_regex:attribute namespace "cl" is unrecognized
5+
//match_regex:attribute namespace "gn" is unrecognized
6+
//match_regex:attribute namespace "g" is unrecognized
7+
//match_regex:attribute namespace "ms" is unrecognized
8+
//match_regex:attribute namespace "_Cl" is unrecognized
9+
//match_regex:\A(?![\s\S]*attribute namespace "(gnu|__gnu__|clang|_Clang|msvc)" is unrecognized)
10+
// 10/14/26 [GH #305]
11+
//
12+
// A namespace that is only a prefix of a namespace known to the front end
13+
// ("clang", "gnu", "msvc", "_Clang") is not recognized: it gets the
14+
// "attribute namespace is unrecognized" warning like any other unknown one.
15+
// The known namespaces themselves are still recognized: they get the
16+
// "unknown attribute" warning for the unknown attribute name only (the last
17+
// regular expression above fails if one of them is reported as unrecognized).
18+
19+
[[cl::x]] int a;
20+
[[gn::y]] int b;
21+
[[g::z]] int c;
22+
[[ms::w]] int d;
23+
[[_Cl::v]] int e;
24+
25+
[[gnu::x]] int f;
26+
[[__gnu__::x]] int g;
27+
[[clang::x]] int h;
28+
[[msvc::x]] int i;
29+
[[_Clang::x]] int j;

0 commit comments

Comments
 (0)