Skip to content

Commit 0abb057

Browse files
committed
Restrict redeclaration of tags introduced by using decls to MSVCCompat
This limits the facility added in r199490 while we seek clarification on the standard. llvm-svn: 199531
1 parent 8d7a6f2 commit 0abb057

File tree

3 files changed

+24
-23
lines changed

3 files changed

+24
-23
lines changed

clang/lib/Sema/SemaDecl.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10681,8 +10681,9 @@ Decl *Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK,
1068110681
}
1068210682

1068310683
if (!Previous.empty()) {
10684-
NamedDecl *DirectPrevDecl = *Previous.begin();
10685-
NamedDecl *PrevDecl = DirectPrevDecl->getUnderlyingDecl();
10684+
NamedDecl *PrevDecl = Previous.getFoundDecl();
10685+
NamedDecl *DirectPrevDecl =
10686+
getLangOpts().MSVCCompat ? *Previous.begin() : PrevDecl;
1068610687

1068710688
// It's okay to have a tag decl in the same scope as a typedef
1068810689
// which hides a tag decl in the same scope. Finding this

clang/test/SemaCXX/MicrosoftCompatibility.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,27 @@ class C : public B {
120120

121121
}
122122

123+
namespace using_tag_redeclaration
124+
{
125+
struct S;
126+
namespace N {
127+
using ::using_tag_redeclaration::S;
128+
struct S {}; // expected-note {{previous definition is here}}
129+
}
130+
void f() {
131+
N::S s1;
132+
S s2;
133+
}
134+
void g() {
135+
struct S; // expected-note {{forward declaration of 'S'}}
136+
S s3; // expected-error {{variable has incomplete type 'S'}}
137+
}
138+
void h() {
139+
using ::using_tag_redeclaration::S;
140+
struct S {}; // expected-error {{redefinition of 'S'}}
141+
}
142+
}
143+
123144

124145
namespace MissingTypename {
125146

clang/test/SemaCXX/using-decl-1.cpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -119,27 +119,6 @@ namespace foo
119119
};
120120
}
121121

122-
namespace using_tag_redeclaration
123-
{
124-
struct S;
125-
namespace N {
126-
using ::using_tag_redeclaration::S;
127-
struct S {}; // expected-note {{previous definition is here}}
128-
}
129-
void f() {
130-
N::S s1;
131-
S s2;
132-
}
133-
void g() {
134-
struct S; // expected-note {{forward declaration of 'S'}}
135-
S s3; // expected-error {{variable has incomplete type 'S'}}
136-
}
137-
void h() {
138-
using ::using_tag_redeclaration::S;
139-
struct S {}; // expected-error {{redefinition of 'S'}}
140-
}
141-
}
142-
143122
// Don't suggest non-typenames for positions requiring typenames.
144123
namespace using_suggestion_tyname_val {
145124
namespace N { void FFF() {} }

0 commit comments

Comments
 (0)