[Bug c++/84897] New: Better handling of unqualified "string"
dmalcolm at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Mar 16 02:14:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84897
Bug ID: 84897
Summary: Better handling of unqualified "string"
Product: gcc
Version: 8.0
Status: UNCONFIRMED
Keywords: diagnostic
Severity: normal
Priority: P3
Component: c++
Assignee: dmalcolm at gcc dot gnu.org
Reporter: dmalcolm at gcc dot gnu.org
Target Milestone: ---
Reddit user "Boojum" suggested:
> As far as other paper cuts, here's one that catches me
> surprisingly frequently:
#include <string>
int main() {
string x("foo");
}
> Obviously, I "forgot" to either qualify string as std::string,
> add using namespace std;, or add using std::string;.
>
> Here's what GCC 7.2 tells me (header paths elided):
namespace.cpp: In function ‘int main()’:
namespace.cpp:3:5: error: ‘string’ was not declared in this scope
string x("foo");
^~~~~~
namespace.cpp:3:5: note: suggested alternatives:
In file included from .../string:39:0,
from namespace.cpp:1:
.../stringfwd.h:74:33: note: ‘std::__cxx11::string’
typedef basic_string<char> string;
^~~~~~
.../stringfwd.h:74:33: note: ‘std::__cxx11::string’
> On the other hand, here's what Clang 6 tells me:
namespace.cpp:3:5: error: unknown type name 'string'; did you mean
'std::string'?
string x("foo");
^~~~~~
std::string
.../stringfwd.h:74:33: note: 'std::string' declared here
typedef basic_string<char> string;
^
1 error generated.
> Much nicer. It tells me exactly which namespace I probably
> meant to use and proposes a fix-it qualifying the identifier.
I hope to fix this for gcc 9.
I'm not yet sure if we want to:
(a) look in "std" when handling such errors (which requires the user to have
included the pertinent header), or
(b) to special-case important "std::" names like "string", or
(c) both
(d) rework the priority of the "look in namespaces" search relative to our
other heuristics
...etc
More information about the Gcc-bugs
mailing list