diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp index bf9fdb6a690db..9f641541ad4b6 100644 --- a/clang/lib/AST/ByteCode/Interp.cpp +++ b/clang/lib/AST/ByteCode/Interp.cpp @@ -1341,6 +1341,9 @@ bool Call(InterpState &S, CodePtr OpPC, const Function *Func, } else { if (!CheckInvoke(S, OpPC, ThisPtr)) return cleanup(); + if (!Func->isConstructor() && + !CheckActive(S, OpPC, ThisPtr, AK_MemberCall)) + return false; } if (Func->isConstructor() && !checkConstructor(S, OpPC, Func, ThisPtr)) diff --git a/clang/test/AST/ByteCode/unions.cpp b/clang/test/AST/ByteCode/unions.cpp index 2064cae11e970..72b9b18609720 100644 --- a/clang/test/AST/ByteCode/unions.cpp +++ b/clang/test/AST/ByteCode/unions.cpp @@ -504,4 +504,22 @@ namespace AnonymousUnion { static_assert(return_init_all().a.p == 7); // both-error {{}} \ // both-note {{read of member 'p' of union with no active member}} } + +namespace MemberCalls { + struct S { + constexpr bool foo() const { return true; } + }; + + constexpr bool foo() { // both-error {{never produces a constant expression}} + union { + int a; + S s; + } u; + + u.a = 10; + return u.s.foo(); // both-note 2{{member call on member 's' of union with active member 'a'}} + } + static_assert(foo()); // both-error {{not an integral constant expression}} \ + // both-note {{in call to}} +} #endif