Index: lib/Sema/SemaExpr.cpp =================================================================== --- lib/Sema/SemaExpr.cpp +++ lib/Sema/SemaExpr.cpp @@ -12414,7 +12414,8 @@ // However, they cannot be referenced if they are deleted, and they are // deleted whenever the implicit definition of the special member would // fail. - if (!Func->isConstexpr() || Func->getBody()) + if (!Func->isConstexpr() || Func->getBody() || + ExprEvalContexts.back().IsDecltype) return; CXXMethodDecl *MD = dyn_cast(Func); if (!Func->isImplicitlyInstantiable() && (!MD || MD->isUserProvided())) Index: test/SemaTemplate/constexpr-instantiate.cpp =================================================================== --- test/SemaTemplate/constexpr-instantiate.cpp +++ test/SemaTemplate/constexpr-instantiate.cpp @@ -77,20 +77,6 @@ } namespace Unevaluated { - // We follow g++ in treating any reference to a constexpr function template - // specialization as requiring an instantiation, even if it occurs in an - // unevaluated context. - // - // We go slightly further than g++, and also trigger the implicit definition - // of a defaulted special member in the same circumstances. This seems scary, - // since a lot of classes have constexpr special members in C++11, but the - // only observable impact should be the implicit instantiation of constexpr - // special member templates (defaulted special members should only be - // generated if they are well-formed, and non-constexpr special members in a - // base or member cause the class's special member to not be constexpr). - // - // FIXME: None of this is required by the C++ standard. The rules in this - // area are poorly specified, so this is subject to change. namespace NotConstexpr { template struct S { S() : n(0) {} @@ -98,16 +84,16 @@ int n; }; struct U : S {}; - decltype(U(U())) u; // ok, don't instantiate S::S() because it wasn't declared constexpr + decltype(U(U())) u; // ok, don't instantiate S::S() } namespace Constexpr { template struct S { constexpr S() : n(0) {} - constexpr S(const S&) : n(T::error) {} // expected-error {{has no members}} + constexpr S(const S&) : n(T::error) {} int n; }; - struct U : S {}; // expected-note {{instantiation}} - decltype(U(U())) u; // expected-note {{here}} + struct U : S {}; + decltype(U(U())) u; // ok, don't instantiate S::S() } namespace PR11851_Comment0 {