r329517 - [Sema] Fix PR22637 - IndirectFieldDecl's discard qualifiers during template instantiation.
Eric Fiselier via cfe-commits
cfe-commits at lists.llvm.org
Sat Apr 7 22:11:59 PDT 2018
Author: ericwf
Date: Sat Apr 7 22:11:59 2018
New Revision: 329517
URL: http://llvm.org/viewvc/llvm-project?rev=329517&view=rev
Log:
[Sema] Fix PR22637 - IndirectFieldDecl's discard qualifiers during template instantiation.
Summary:
Currently Clang fails to propagate qualifiers from the `CXXThisExpr` to the rebuilt `FieldDecl` for IndirectFieldDecls. For example:
```
template <class T> struct Foo {
struct { int x; };
int y;
void foo() const {
static_assert(__is_same(int const&, decltype((y))));
static_assert(__is_same(int const&, decltype((x)))); // assertion fails
}
};
template struct Foo<int>;
```
The fix is to delegate rebuilding of the MemberExpr to `BuildFieldReferenceExpr` which correctly propagates the qualifiers.
Reviewers: rsmith, lebedev.ri, aaron.ballman, bkramer, rjmccall
Reviewed By: rjmccall
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D45412
Added:
cfe/trunk/test/SemaCXX/PR22637.cpp
Modified:
cfe/trunk/lib/Sema/TreeTransform.h
cfe/trunk/test/SemaCXX/cxx0x-nontrivial-union.cpp
Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=329517&r1=329516&r2=329517&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Sat Apr 7 22:11:59 2018
@@ -2250,11 +2250,11 @@ public:
if (BaseResult.isInvalid())
return ExprError();
Base = BaseResult.get();
- ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
- MemberExpr *ME = new (getSema().Context)
- MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
- cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
- return ME;
+
+ CXXScopeSpec EmptySS;
+ return getSema().BuildFieldReferenceExpr(
+ Base, isArrow, OpLoc, EmptySS, cast<FieldDecl>(Member),
+ DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()), MemberNameInfo);
}
CXXScopeSpec SS;
Added: cfe/trunk/test/SemaCXX/PR22637.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/PR22637.cpp?rev=329517&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/PR22637.cpp (added)
+++ cfe/trunk/test/SemaCXX/PR22637.cpp Sat Apr 7 22:11:59 2018
@@ -0,0 +1,40 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// expected-no-diagnostics
+
+void check(int&) = delete;
+void check(int const&) { }
+
+template <typename>
+struct A {
+ union {
+ int b;
+ };
+ struct {
+ int c;
+ };
+ union {
+ struct {
+ union {
+ struct {
+ struct {
+ int d;
+ };
+ };
+ };
+ };
+ };
+ int e;
+ void foo() const {
+ check(b);
+ check(c);
+ check(d);
+ check(d);
+ check(e);
+ }
+};
+
+int main(){
+ A<int> a;
+ a.foo();
+}
Modified: cfe/trunk/test/SemaCXX/cxx0x-nontrivial-union.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx0x-nontrivial-union.cpp?rev=329517&r1=329516&r2=329517&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx0x-nontrivial-union.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx0x-nontrivial-union.cpp Sat Apr 7 22:11:59 2018
@@ -110,7 +110,7 @@ namespace optional {
}
explicit operator bool() const { return has; }
- T &operator*() const { return value; }
+ T &operator*() { return value; }
};
optional<non_trivial> o1;
More information about the cfe-commits
mailing list