C++: show location of unclosed extern "C" specifications
commitc7cae1379b85604b30ef84aa3fffde2ec8532066
authordmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 13 Oct 2017 12:42:39 +0000 (13 12:42 +0000)
committerdmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 13 Oct 2017 12:42:39 +0000 (13 12:42 +0000)
tree7b2e27753270c83805872cbc3270007b040ce3bb
parent32973e22775a88be8045ae89accb09f4e642c29a
C++: show location of unclosed extern "C" specifications

If the user fails to close an extern "C" linkage specifier, and then
uses templates, they will run into "template with C linkage" errors.

From personal experience, it can be hard to tell where the
extern "C" began.  As of r251026 there will be a message highlighting
the unclosed '{', but this may be hard to spot at the very end of
the errors.

This patch adds a note to the various diagnostics that complain
about C linkage, showing the user where the extern "C" specification
began.

gcc/cp/ChangeLog:
* cp-tree.h (maybe_show_extern_c_location): New decl.
* decl.c (grokfndecl): When complaining about literal operators
with C linkage, issue a note giving the location of the
extern "C".
* parser.c (cp_parser_new): Initialize new field
"innermost_linkage_specification_location".
(cp_parser_linkage_specification): Store the location
of the linkage specification within the cp_parser.
(cp_parser_explicit_specialization): When complaining about
template specializations with C linkage, issue a note giving the
location of the extern "C".
(cp_parser_explicit_template_declaration): Likewise for templates.
(maybe_show_extern_c_location): New function.
* parser.h (struct cp_parser): New field
"innermost_linkage_specification_location".

gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/udlit-extern-c.C: New test case.
* g++.dg/diagnostic/unclosed-extern-c.C: Add example of a template
erroneously covered by an unclosed extern "C".
* g++.dg/template/extern-c.C: New test case.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@253726 138bc75d-0d04-0410-961f-82ee72b054a4
gcc/cp/ChangeLog
gcc/cp/cp-tree.h
gcc/cp/decl.c
gcc/cp/parser.c
gcc/cp/parser.h
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/udlit-extern-c.C [new file with mode: 0644]
gcc/testsuite/g++.dg/diagnostic/unclosed-extern-c.C
gcc/testsuite/g++.dg/template/extern-c.C [new file with mode: 0644]