[Bug c++/88121] New: Nonsensical messages when suggesting names from other namespaces
dmalcolm at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Nov 20 20:07:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88121
Bug ID: 88121
Summary: Nonsensical messages when suggesting names from other
namespaces
Product: gcc
Version: unknown
Status: UNCONFIRMED
Keywords: diagnostic
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: dmalcolm at gcc dot gnu.org
Target Milestone: ---
Consider this code:
namespace json
{
enum { JSON_OBJECT };
}
void test ()
{
JSON_OBJECT;
}
gcc 6 through 8 emit:
<source>: In function 'void test()':
<source>:8:3: error: 'JSON_OBJECT' was not declared in this scope
JSON_OBJECT;
^~~~~~~~~~~
<source>:8:3: note: suggested alternative:
<source>:3:10: note: 'JSON_OBJECT'
enum { JSON_OBJECT };
^~~~~~~~~~~
...suggesting the use of json::JSON_OBJECT, though without spelling out the
namespace prefix.
As of r265610, gcc 9 consolidates the single suggestion into the error, and
emits:
<source>: In function 'void test()':
<source>:8:3: error: 'JSON_OBJECT' was not declared in this scope; did you mean
'JSON_OBJECT'?
8 | JSON_OBJECT;
| ^~~~~~~~~~~
| JSON_OBJECT
<source>:3:10: note: 'JSON_OBJECT' declared here
3 | enum { JSON_OBJECT };
| ^~~~~~~~~~~
The message:
'JSON_OBJECT' was not declared in this scope; did you mean 'JSON_OBJECT'?
is nonsensical.
Presumably we should emit a suggestion with an explicit namespace, e.g.:
<source>: In function 'void test()':
<source>:8:3: error: 'JSON_OBJECT' was not declared in this scope; did you mean
'json::JSON_OBJECT'?
8 | JSON_OBJECT;
| ^~~~~~~~~~~
| json::JSON_OBJECT
<source>:3:10: note: 'json::JSON_OBJECT' declared here
3 | enum { JSON_OBJECT };
| ^~~~~~~~~~~
More information about the Gcc-bugs
mailing list