C++: show location of unclosed extern "C" specifications
authorDavid Malcolm <dmalcolm@redhat.com>
Fri, 13 Oct 2017 12:42:39 +0000 (12:42 +0000)
committerDavid Malcolm <dmalcolm@gcc.gnu.org>
Fri, 13 Oct 2017 12:42:39 +0000 (12:42 +0000)
commit15f7a4692667ce38eed325a9567f5ef492a5ce07
tree7b2e27753270c83805872cbc3270007b040ce3bb
parent3b0dd4fea23a695df1fb9a7e5c7017f9d1f1ea84
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.

From-SVN: r253726
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]