if (isa<ParmVarDecl>(this))
return false;
+ // The values of weak variables are never usable in constant expressions.
+ if (isWeak())
+ return false;
+
// In C++11, any variable of reference type can be used in a constant
// expression if it is initialized by a constant expression.
if (Lang.CPlusPlus11 && getType()->isReferenceType())
}
bool VarDecl::checkInitIsICE() const {
- // Initializers of weak variables are never ICEs.
- if (isWeak())
- return false;
-
EvaluatedStmt *Eval = ensureEvaluatedStmt();
if (Eval->CheckedICE)
// We have already checked whether this subexpression is an
const VarDecl *VD;
// Look for a declaration of this variable that has an initializer, and
// check whether it is an ICE.
- if (Dcl->getAnyInitializer(VD) && VD->checkInitIsICE())
+ if (Dcl->getAnyInitializer(VD) && !VD->isWeak() && VD->checkInitIsICE())
return NoDiag();
else
return ICEDiag(IK_NotICE, cast<DeclRefExpr>(E)->getLocation());
// might be foobar, including it failing to be a constant expression.
// TODO Handle more ways the lookup or result can be invalid.
if (!VD->isStaticDataMember() || !VD->isConstexpr() || !VD->hasInit() ||
- !VD->checkInitIsICE())
+ VD->isWeak() || !VD->checkInitIsICE())
return UnsupportedSTLError(USS_InvalidMember, MemName, VD);
// Attempt to evaluate the var decl as a constant expression and extract
--- /dev/null
+// RUN: %clang_cc1 %s -std=c++20 -verify
+// expected-no-diagnostics
+
+constinit int a __attribute__((weak)) = 0;