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
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@329517
91177308-0d34-0410-b5e6-
96231b3b80d8
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;
--- /dev/null
+// 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();
+}
}
explicit operator bool() const { return has; }
- T &operator*() const { return value; }
+ T &operator*() { return value; }
};
optional<non_trivial> o1;