diff options
author | Nathaniel Shead <nathanieloshead@gmail.com> | 2024-10-04 12:01:38 +1000 |
---|---|---|
committer | Nathaniel Shead <nathanieloshead@gmail.com> | 2024-10-04 20:30:04 +1000 |
commit | 247643c7e21b087e6c93b8b8d49b4268bf84b03b (patch) | |
tree | a87f2eb8832ba8b9d7aecfe9e1bf7bea0f679ad0 /gcc/cp/parser.cc | |
parent | 6a1e109158940ce3a2d1ceed3e1b614ea6c9a2de (diff) | |
download | gcc-247643c7e21b087e6c93b8b8d49b4268bf84b03b.zip gcc-247643c7e21b087e6c93b8b8d49b4268bf84b03b.tar.gz gcc-247643c7e21b087e6c93b8b8d49b4268bf84b03b.tar.bz2 |
c++: Allow references to internal-linkage vars in C++11 [PR113266]
[temp.arg.nontype] changed in C++11 to allow naming internal-linkage
variables and functions. We currently already handle internal-linkage
functions, but variables were missed; this patch updates this.
PR c++/113266
PR c++/116911
gcc/cp/ChangeLog:
* parser.cc (cp_parser_template_argument): Allow
internal-linkage variables since C++11.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/nontype6.C: New test.
Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Diffstat (limited to 'gcc/cp/parser.cc')
-rw-r--r-- | gcc/cp/parser.cc | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 08f9c89..9d31a97 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -19864,9 +19864,11 @@ cp_parser_template_argument (cp_parser* parser) -- the name of a non-type template-parameter; or - -- the name of an object or function with external linkage... + -- the name of an object or function with external (or internal, + since C++11) linkage... - -- the address of an object or function with external linkage... + -- the address of an object or function with external (or internal, + since C++11) linkage... -- a pointer to member... */ /* Look for a non-type template parameter. */ @@ -19929,11 +19931,16 @@ cp_parser_template_argument (cp_parser* parser) probe = TREE_OPERAND (probe, 1); if (VAR_P (probe)) { - /* A variable without external linkage might still be a + /* A variable without valid linkage might still be a valid constant-expression, so no error is issued here if the external-linkage check fails. */ - if (!address_p && !DECL_EXTERNAL_LINKAGE_P (probe)) - cp_parser_simulate_error (parser); + if (!address_p) + { + linkage_kind linkage = decl_linkage (probe); + if (linkage != lk_external + && (cxx_dialect < cxx11 || linkage != lk_internal)) + cp_parser_simulate_error (parser); + } } else if (is_overloaded_fn (argument)) /* All overloaded functions are allowed; if the external |