Skip to content

Revert "Merge pull request #9200 from compnerd/static_assert_false" #9215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 10 additions & 3 deletions clang/lib/Sema/SemaDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17146,14 +17146,21 @@ Decl *Sema::BuildStaticAssertDeclaration(SourceLocation StaticAssertLoc,
FoldKind).isInvalid())
Failed = true;

// If the static_assert passes, only verify that
// the message is grammatically valid without evaluating it.
if (!Failed && AssertMessage && Cond.getBoolValue()) {
std::string Str;
EvaluateStaticAssertMessageAsString(AssertMessage, Str, Context,
/*ErrorOnInvalidMessage=*/false);
}

// CWG2518
// [dcl.pre]/p10 If [...] the expression is evaluated in the context of a
// template definition, the declaration has no effect.
bool InTemplateDefinition =
getLangOpts().CPlusPlus && CurContext->isDependentContext();

if (!Failed && !Cond && !InTemplateDefinition) {

SmallString<256> MsgBuffer;
llvm::raw_svector_ostream Msg(MsgBuffer);
bool HasMessage = AssertMessage;
Expand Down Expand Up @@ -17185,8 +17192,8 @@ Decl *Sema::BuildStaticAssertDeclaration(SourceLocation StaticAssertLoc,
<< InnerCond->getSourceRange();
DiagnoseStaticAssertDetails(InnerCond);
} else {
Diag(StaticAssertLoc, diag::err_static_assert_failed)
<< !AssertMessage << Msg.str() << AssertExpr->getSourceRange();
Diag(AssertExpr->getBeginLoc(), diag::err_static_assert_failed)
<< !HasMessage << Msg.str() << AssertExpr->getSourceRange();
PrintContextStack();
}
Failed = true;
Expand Down
34 changes: 0 additions & 34 deletions clang/test/CXX/drs/dr25xx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,40 +81,6 @@ using ::dr2521::operator""_div;
#endif
} // namespace dr2521

namespace dr2518 { // dr2518: 17 review

template <class T>
void f(T t) {
if constexpr (sizeof(T) != sizeof(int)) {
static_assert(false, "must be int-sized"); // expected-error {{must be int-size}}
}
}

void g(char c) {
f(0);
f(c); // expected-note {{requested here}}
}

template <typename Ty>
struct S {
static_assert(false); // expected-error {{static assertion failed}}
};

template <>
struct S<int> {};

template <>
struct S<float> {};

int test_specialization() {
S<int> s1;
S<float> s2;
S<double> s3; // expected-note {{in instantiation of template class 'dr2518::S<double>' requested here}}
}

}


namespace dr2565 { // dr2565: 16 open
#if __cplusplus >= 202002L
template<typename T>
Expand Down