Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions clang/lib/AST/ExprConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4450,7 +4450,8 @@ static CompleteObject findCompleteObject(EvalInfo &Info, const Expr *E,
}
} else if (!IsAccess) {
return CompleteObject(LVal.getLValueBase(), nullptr, BaseType);
} else if (IsConstant && Info.checkingPotentialConstantExpression() &&
} else if ((IsConstant || BaseType->isReferenceType()) &&
Info.checkingPotentialConstantExpression() &&
BaseType->isLiteralType(Info.Ctx) && !VD->hasDefinition()) {
// This variable might end up being constexpr. Don't diagnose it yet.
} else if (IsConstant) {
Expand Down Expand Up @@ -4491,9 +4492,11 @@ static CompleteObject findCompleteObject(EvalInfo &Info, const Expr *E,
// a null BaseVal. Any constexpr-unknown variable seen here is an error:
// we can't access a constexpr-unknown object.
if (AK != clang::AK_Dereference && !BaseVal) {
Info.FFDiag(E, diag::note_constexpr_access_unknown_variable, 1)
<< AK << VD;
Info.Note(VD->getLocation(), diag::note_declared_at);
if (!Info.checkingPotentialConstantExpression()) {
Info.FFDiag(E, diag::note_constexpr_access_unknown_variable, 1)
<< AK << VD;
Info.Note(VD->getLocation(), diag::note_declared_at);
}
return CompleteObject();
}
} else if (DynamicAllocLValue DA = LVal.Base.dyn_cast<DynamicAllocLValue>()) {
Expand Down
24 changes: 24 additions & 0 deletions clang/test/SemaCXX/constant-expression-p2280r4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,3 +357,27 @@ namespace pointer_comparisons {
static_assert(!f4()); // expected-error {{static assertion expression is not an integral constant expression}} \
// expected-note {{in call to 'f4()'}}
}

namespace enable_if_1 {
template <__SIZE_TYPE__ N>
constexpr void foo(const char (&Str)[N])
__attribute((enable_if(__builtin_strlen(Str), ""))) {}

void x() {
foo("1234");
}
}

namespace enable_if_2 {
constexpr const char (&f())[];
extern const char (&Str)[];
constexpr int foo()
__attribute((enable_if(__builtin_strlen(Str), "")))
{return __builtin_strlen(Str);}

constexpr const char (&f())[] {return "a";}
constexpr const char (&Str)[] = f();
void x() {
constexpr int x = foo();
}
}
Comment on lines +362 to +384
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you reference the issue (either a comment or in the namespace name)?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We normally use the namespace name, I think we should stick w/ that.

5 changes: 5 additions & 0 deletions clang/test/SemaCXX/constexpr-never-constant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ constexpr void other_func() {

throw 12;
}

// Make sure these don't trigger the diagnostic.
extern const bool& b;
constexpr bool fun1() { return b; }
constexpr bool fun2(const bool& b) { return b; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you reference the issue (either a comment or in the namespace name)?