From: Alp Toker Date: Sat, 18 Jan 2014 00:59:32 +0000 (+0000) Subject: Restrict redeclaration of tags introduced by using decls to MSVCCompat X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1ee6ed2aed0f076a7144df8fdd503b84702b7190;p=clang Restrict redeclaration of tags introduced by using decls to MSVCCompat This limits the facility added in r199490 while we seek clarification on the standard. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@199531 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 62fedbf969..f71540c204 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -10681,8 +10681,9 @@ Decl *Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, } if (!Previous.empty()) { - NamedDecl *DirectPrevDecl = *Previous.begin(); - NamedDecl *PrevDecl = DirectPrevDecl->getUnderlyingDecl(); + NamedDecl *PrevDecl = Previous.getFoundDecl(); + NamedDecl *DirectPrevDecl = + getLangOpts().MSVCCompat ? *Previous.begin() : PrevDecl; // It's okay to have a tag decl in the same scope as a typedef // which hides a tag decl in the same scope. Finding this diff --git a/test/SemaCXX/MicrosoftCompatibility.cpp b/test/SemaCXX/MicrosoftCompatibility.cpp index 1f27deb0ee..0971646e73 100644 --- a/test/SemaCXX/MicrosoftCompatibility.cpp +++ b/test/SemaCXX/MicrosoftCompatibility.cpp @@ -120,6 +120,27 @@ private: } +namespace using_tag_redeclaration +{ + struct S; + namespace N { + using ::using_tag_redeclaration::S; + struct S {}; // expected-note {{previous definition is here}} + } + void f() { + N::S s1; + S s2; + } + void g() { + struct S; // expected-note {{forward declaration of 'S'}} + S s3; // expected-error {{variable has incomplete type 'S'}} + } + void h() { + using ::using_tag_redeclaration::S; + struct S {}; // expected-error {{redefinition of 'S'}} + } +} + namespace MissingTypename { diff --git a/test/SemaCXX/using-decl-1.cpp b/test/SemaCXX/using-decl-1.cpp index ed5cce7c97..24d92f175c 100644 --- a/test/SemaCXX/using-decl-1.cpp +++ b/test/SemaCXX/using-decl-1.cpp @@ -119,27 +119,6 @@ namespace foo }; } -namespace using_tag_redeclaration -{ - struct S; - namespace N { - using ::using_tag_redeclaration::S; - struct S {}; // expected-note {{previous definition is here}} - } - void f() { - N::S s1; - S s2; - } - void g() { - struct S; // expected-note {{forward declaration of 'S'}} - S s3; // expected-error {{variable has incomplete type 'S'}} - } - void h() { - using ::using_tag_redeclaration::S; - struct S {}; // expected-error {{redefinition of 'S'}} - } -} - // Don't suggest non-typenames for positions requiring typenames. namespace using_suggestion_tyname_val { namespace N { void FFF() {} }