diff --git a/src/Changes b/src/Changes index de5c529b76..df3a576af0 100644 --- a/src/Changes +++ b/src/Changes @@ -1,5 +1,16 @@ Version 7.1 +10/15/26 [GH #305] +Attribute namespaces that only start like a known one are not recognized + +An attribute namespace was treated as known if it was merely the first part +of the name of a known namespace, so a namespace such as "cl", "g" or "ms" +was accepted as if it were "clang", "gnu" or "msvc". The whole name must +now match. For example: + + [[cl::x]] int a; // Warning: attribute namespace "cl" is unrecognized + [[g::y]] int b; // Previously, the namespace was accepted. + 10/9/26 [GH #27] Clearer diagnostic when auto is deduced from an incomplete type diff --git a/src/attribute.c b/src/attribute.c index 86c8b0a627..630f4a949c 100644 --- a/src/attribute.c +++ b/src/attribute.c @@ -1096,7 +1096,9 @@ namespace. If non-zero, length represents the number of characters in name length = strlen(name); } /* if */ for (np = valid_attribute_namespaces; *np != NULL; np++) { - if (strncmp(*np, name, length) == 0) { + /* The whole name must match: a name that is only a prefix of a known + namespace (e.g., "cl" or "g") is not recognized. */ + if (strncmp(*np, name, length) == 0 && (*np)[length] == '\0') { result = TRUE; break; } /* if */ diff --git a/tests/tests/changes/.GH-ns-exact.rto/default.1.1.txt b/tests/tests/changes/.GH-ns-exact.rto/default.1.1.txt new file mode 100644 index 0000000000..f4be6205c7 --- /dev/null +++ b/tests/tests/changes/.GH-ns-exact.rto/default.1.1.txt @@ -0,0 +1,41 @@ +fe_only -DTEST_NUMBER=1 --c++17 Test_name.c +"Test_name.c", line 19: warning: attribute namespace "cl" is unrecognized + [[cl::x]] int a; + ^ + +"Test_name.c", line 20: warning: attribute namespace "gn" is unrecognized + [[gn::y]] int b; + ^ + +"Test_name.c", line 21: warning: attribute namespace "g" is unrecognized + [[g::z]] int c; + ^ + +"Test_name.c", line 22: warning: attribute namespace "ms" is unrecognized + [[ms::w]] int d; + ^ + +"Test_name.c", line 23: warning: attribute namespace "_Cl" is unrecognized + [[_Cl::v]] int e; + ^ + +"Test_name.c", line 25: warning: unknown attribute "gnu::x" + [[gnu::x]] int f; + ^ + +"Test_name.c", line 26: warning: unknown attribute "__gnu__::x" + [[__gnu__::x]] int g; + ^ + +"Test_name.c", line 27: warning: unknown attribute "clang::x" + [[clang::x]] int h; + ^ + +"Test_name.c", line 28: warning: unknown attribute "msvc::x" + [[msvc::x]] int i; + ^ + +"Test_name.c", line 29: warning: unknown attribute "_Clang::x" + [[_Clang::x]] int j; + ^ + diff --git a/tests/tests/changes/.GH-ns-exact.rto/default.1.matches.txt b/tests/tests/changes/.GH-ns-exact.rto/default.1.matches.txt new file mode 100644 index 0000000000..9aa901a538 --- /dev/null +++ b/tests/tests/changes/.GH-ns-exact.rto/default.1.matches.txt @@ -0,0 +1,24 @@ +Matches for "attribute namespace "cl" is unrecognized": + <----------------------------------------------------------------------------- + attribute namespace "cl" is unrecognized + -----------------------------------------------------------------------------> +Matches for "attribute namespace "gn" is unrecognized": + <----------------------------------------------------------------------------- + attribute namespace "gn" is unrecognized + -----------------------------------------------------------------------------> +Matches for "attribute namespace "g" is unrecognized": + <----------------------------------------------------------------------------- + attribute namespace "g" is unrecognized + -----------------------------------------------------------------------------> +Matches for "attribute namespace "ms" is unrecognized": + <----------------------------------------------------------------------------- + attribute namespace "ms" is unrecognized + -----------------------------------------------------------------------------> +Matches for "attribute namespace "_Cl" is unrecognized": + <----------------------------------------------------------------------------- + attribute namespace "_Cl" is unrecognized + -----------------------------------------------------------------------------> +Matches for "\A(?![\s\S]*attribute namespace "(gnu|__gnu__|clang|_Clang|msvc)" is unrecognized)": + <----------------------------------------------------------------------------- + + -----------------------------------------------------------------------------> diff --git a/tests/tests/changes/.GH-ns-exact.rto/edg_x86_32_cp.1.1.txt b/tests/tests/changes/.GH-ns-exact.rto/edg_x86_32_cp.1.1.txt new file mode 100644 index 0000000000..c601710a51 --- /dev/null +++ b/tests/tests/changes/.GH-ns-exact.rto/edg_x86_32_cp.1.1.txt @@ -0,0 +1,21 @@ +fe_only -DTEST_NUMBER=1 --c++17 Test_name.c +"Test_name.c", line 19: warning: attribute namespace "cl" is unrecognized + [[cl::x]] int a; + ^ + +"Test_name.c", line 20: warning: attribute namespace "gn" is unrecognized + [[gn::y]] int b; + ^ + +"Test_name.c", line 21: warning: attribute namespace "g" is unrecognized + [[g::z]] int c; + ^ + +"Test_name.c", line 22: warning: attribute namespace "ms" is unrecognized + [[ms::w]] int d; + ^ + +"Test_name.c", line 23: warning: attribute namespace "_Cl" is unrecognized + [[_Cl::v]] int e; + ^ + diff --git a/tests/tests/changes/.GH-ns-exact.rto/edg_x86_64_cp.1.1.txt b/tests/tests/changes/.GH-ns-exact.rto/edg_x86_64_cp.1.1.txt new file mode 100644 index 0000000000..c601710a51 --- /dev/null +++ b/tests/tests/changes/.GH-ns-exact.rto/edg_x86_64_cp.1.1.txt @@ -0,0 +1,21 @@ +fe_only -DTEST_NUMBER=1 --c++17 Test_name.c +"Test_name.c", line 19: warning: attribute namespace "cl" is unrecognized + [[cl::x]] int a; + ^ + +"Test_name.c", line 20: warning: attribute namespace "gn" is unrecognized + [[gn::y]] int b; + ^ + +"Test_name.c", line 21: warning: attribute namespace "g" is unrecognized + [[g::z]] int c; + ^ + +"Test_name.c", line 22: warning: attribute namespace "ms" is unrecognized + [[ms::w]] int d; + ^ + +"Test_name.c", line 23: warning: attribute namespace "_Cl" is unrecognized + [[_Cl::v]] int e; + ^ + diff --git a/tests/tests/changes/GH-ns-exact.sft.cpp b/tests/tests/changes/GH-ns-exact.sft.cpp new file mode 100644 index 0000000000..da5409fb5b --- /dev/null +++ b/tests/tests/changes/GH-ns-exact.sft.cpp @@ -0,0 +1,29 @@ +//type:fp +//options:--c++17 +//remark:[GH #305] Attribute namespaces that only start like a known one +//match_regex:attribute namespace "cl" is unrecognized +//match_regex:attribute namespace "gn" is unrecognized +//match_regex:attribute namespace "g" is unrecognized +//match_regex:attribute namespace "ms" is unrecognized +//match_regex:attribute namespace "_Cl" is unrecognized +//match_regex:\A(?![\s\S]*attribute namespace "(gnu|__gnu__|clang|_Clang|msvc)" is unrecognized) +// 10/14/26 [GH #305] +// +// A namespace that is only a prefix of a namespace known to the front end +// ("clang", "gnu", "msvc", "_Clang") is not recognized: it gets the +// "attribute namespace is unrecognized" warning like any other unknown one. +// The known namespaces themselves are still recognized: they get the +// "unknown attribute" warning for the unknown attribute name only (the last +// regular expression above fails if one of them is reported as unrecognized). + +[[cl::x]] int a; +[[gn::y]] int b; +[[g::z]] int c; +[[ms::w]] int d; +[[_Cl::v]] int e; + +[[gnu::x]] int f; +[[__gnu__::x]] int g; +[[clang::x]] int h; +[[msvc::x]] int i; +[[_Clang::x]] int j;