diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index a3c06fdae8e..3d605dc2340 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -7240,7 +7240,8 @@ make_rtl_for_nonlocal_decl (tree decl, tree init, const char* asmspec) This is horrible, as we're affecting a possibly-shared decl. Again, a one-true-decl model breaks down. */ - set_user_assembler_name (ns_decl, asmspec); + if (ns_decl != error_mark_node) + set_user_assembler_name (ns_decl, asmspec); } } diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index ef9fdddc86e..c9ac3db4d98 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -3477,7 +3477,9 @@ push_local_extern_decl_alias (tree decl) push_nested_namespace (ns); alias = do_pushdecl (alias, /* hiding= */true); pop_nested_namespace (ns); - if (VAR_P (decl) && CP_DECL_THREAD_LOCAL_P (decl)) + if (VAR_P (decl) + && CP_DECL_THREAD_LOCAL_P (decl) + && alias != error_mark_node) set_decl_tls_model (alias, DECL_TLS_MODEL (decl)); } } diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 40456a9dc5c..030341640e9 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -42359,7 +42359,8 @@ cp_parser_oacc_declare (cp_parser *parser, cp_token *pragma_tok) dependent local extern variable decls are as rare as hen's teeth. */ if (auto alias = DECL_LOCAL_DECL_ALIAS (decl)) - decl = alias; + if (alias != error_mark_node) + decl = alias; if (OMP_CLAUSE_MAP_KIND (t) == GOMP_MAP_LINK) id = get_identifier ("omp declare target link"); @@ -43428,7 +43429,8 @@ cp_parser_omp_declare_target (cp_parser *parser, cp_token *pragma_tok) if (VAR_OR_FUNCTION_DECL_P (t) && DECL_LOCAL_DECL_P (t) && DECL_LANG_SPECIFIC (t) - && DECL_LOCAL_DECL_ALIAS (t)) + && DECL_LOCAL_DECL_ALIAS (t) + && DECL_LOCAL_DECL_ALIAS (t) != error_mark_node) handle_omp_declare_target_clause (c, DECL_LOCAL_DECL_ALIAS (t), device_type); } diff --git a/gcc/testsuite/g++.dg/tls/pr102642.C b/gcc/testsuite/g++.dg/tls/pr102642.C new file mode 100644 index 00000000000..e3236d3dfdb --- /dev/null +++ b/gcc/testsuite/g++.dg/tls/pr102642.C @@ -0,0 +1,10 @@ +// PR c++/102642 +// { dg-do compile { target c++11 } } + +thread_local int *z; // { dg-message "previous declaration" } + +void +foo () +{ + extern thread_local int z; // { dg-error "conflicting declaration" } +}