From 3cbf3f1f597e7ba95a2c8161d8b14a9b8a4e904b Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Fri, 15 Jul 2016 20:53:25 +0000 Subject: [PATCH] Push alias-declarations and alias-template declarations into scope even if they're redeclarations. This is necessary in order for name lookup to correctly find the most recent declaration of the name (which affects default template argument lookup and cross-module merging, among other things). llvm-svn: 275612 --- clang/lib/Sema/SemaDeclCXX.cpp | 4 +--- clang/test/CXX/dcl.dcl/dcl.spec/dcl.typedef/p2-0x.cpp | 4 ++-- clang/test/CXX/drs/dr6xx.cpp | 4 ++-- clang/test/CXX/temp/temp.param/p15-cxx0x.cpp | 2 +- clang/test/Modules/submodules-merge-defs.cpp | 7 +++++++ clang/test/SemaCXX/alias-template.cpp | 4 ++-- clang/test/SemaTemplate/alias-templates.cpp | 6 ++++++ 7 files changed, 21 insertions(+), 10 deletions(-) diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 22334ab253cc..e161c87f1739 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -8885,9 +8885,7 @@ Decl *Sema::ActOnAliasDeclaration(Scope *S, NewND = NewTD; } - if (!Redeclaration) - PushOnScopeChains(NewND, S); - + PushOnScopeChains(NewND, S); ActOnDocumentableDecl(NewND); return NewND; } diff --git a/clang/test/CXX/dcl.dcl/dcl.spec/dcl.typedef/p2-0x.cpp b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.typedef/p2-0x.cpp index 20b5104f83be..8c6f6e5ddc79 100644 --- a/clang/test/CXX/dcl.dcl/dcl.spec/dcl.typedef/p2-0x.cpp +++ b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.typedef/p2-0x.cpp @@ -38,8 +38,8 @@ namespace VariableLengthArrays { using T = int[n]; // expected-error {{variable length array declaration not allowed at file scope}} const int m = 42; - using U = int[m]; // expected-note {{previous definition}} - using U = int[42]; // ok + using U = int[m]; + using U = int[42]; // expected-note {{previous definition}} using U = int; // expected-error {{type alias redefinition with different types ('int' vs 'int [42]')}} void f() { diff --git a/clang/test/CXX/drs/dr6xx.cpp b/clang/test/CXX/drs/dr6xx.cpp index 988c8f43011d..1d37a6d3e80c 100644 --- a/clang/test/CXX/drs/dr6xx.cpp +++ b/clang/test/CXX/drs/dr6xx.cpp @@ -146,9 +146,9 @@ namespace dr616 { // dr616: no #if __cplusplus >= 201103L struct S { int n; } s; // FIXME: These should all be 'int &&' - using T = decltype(S().n); // expected-note 2{{previous}} + using T = decltype(S().n); using T = decltype(static_cast(s).n); - using T = decltype(S().*&S::n); + using T = decltype(S().*&S::n); // expected-note 2{{previous}} using T = decltype(static_cast(s).*&S::n); // expected-error {{different type}} using T = int&&; // expected-error {{different type}} #endif diff --git a/clang/test/CXX/temp/temp.param/p15-cxx0x.cpp b/clang/test/CXX/temp/temp.param/p15-cxx0x.cpp index ade192b3efa9..667152da1cbc 100644 --- a/clang/test/CXX/temp/temp.param/p15-cxx0x.cpp +++ b/clang/test/CXX/temp/temp.param/p15-cxx0x.cpp @@ -102,10 +102,10 @@ using D1 = drop<3, int, char, double, long>::type; using D1 = types; using T2 = take<4, int, char, double, long>::type; // expected-note {{previous}} -using T2 = types; // FIXME: Desguar the types on the RHS in this diagnostic. // desired-error {{'types' vs 'types'}} using T2 = types; // expected-error {{'types' vs 'types::type, typename inner<_>::type, typename inner<_>::type, typename inner<_>::type>'}} +using T2 = types; using D2 = drop<4, int, char, double, long>::type; using D2 = types<>; diff --git a/clang/test/Modules/submodules-merge-defs.cpp b/clang/test/Modules/submodules-merge-defs.cpp index 23d1f5cfb12b..4ab822a022bd 100644 --- a/clang/test/Modules/submodules-merge-defs.cpp +++ b/clang/test/Modules/submodules-merge-defs.cpp @@ -58,6 +58,11 @@ G::A pre_ga // expected-error +{{must be imported}} decltype(G::h) pre_gh = G::h; // expected-error +{{must be imported}} // expected-note@defs.h:51 +{{here}} +int pre_h = H(); // expected-error +{{must be imported}} +// expected-note@defs.h:56 +{{here}} +using pre_i = I<>; // expected-error +{{must be imported}} +// expected-note@defs.h:57 +{{here}} + J<> pre_j; // expected-error {{declaration of 'J' must be imported}} #ifdef IMPORT_USE_2 // expected-error-re@-2 {{default argument of 'J' must be imported from one of {{.*}}stuff.use{{.*}}stuff.use-2}} @@ -99,6 +104,8 @@ int post_ff = F().f(); int post_fg = F().g(); G::A post_ga = G::a; decltype(G::h) post_gh = G::h; +int post_h = H(); +using post_i = I<>; J<> post_j; template class K> struct J; J<> post_j2; diff --git a/clang/test/SemaCXX/alias-template.cpp b/clang/test/SemaCXX/alias-template.cpp index bcfe428c69dd..b6256103ef8d 100644 --- a/clang/test/SemaCXX/alias-template.cpp +++ b/clang/test/SemaCXX/alias-template.cpp @@ -35,8 +35,8 @@ namespace VariableLengthArrays { template using T = int[n]; // expected-error {{variable length array declaration not allowed at file scope}} const int m = 42; - template using U = int[m]; // expected-note {{previous definition}} - template using U = int[42]; // ok + template using U = int[m]; + template using U = int[42]; // expected-note {{previous definition}} template using U = int; // expected-error {{type alias template redefinition with different types ('int' vs 'int [42]')}} } diff --git a/clang/test/SemaTemplate/alias-templates.cpp b/clang/test/SemaTemplate/alias-templates.cpp index 1849ff64026b..b7078353ff1b 100644 --- a/clang/test/SemaTemplate/alias-templates.cpp +++ b/clang/test/SemaTemplate/alias-templates.cpp @@ -221,3 +221,9 @@ namespace PR14858 { template void h(X &) {} template void h(X &) {} // ok, different } + +namespace redecl { + template using A = int; + template using A = int; + A<> a; // ok +}