-
Notifications
You must be signed in to change notification settings - Fork 342
[Clang] Implement CWG2518 - static_assert(false) #9200
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17146,21 +17146,14 @@ 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; | ||
|
@@ -17192,8 +17185,8 @@ Decl *Sema::BuildStaticAssertDeclaration(SourceLocation StaticAssertLoc, | |
<< InnerCond->getSourceRange(); | ||
DiagnoseStaticAssertDetails(InnerCond); | ||
} else { | ||
Diag(AssertExpr->getBeginLoc(), diag::err_static_assert_failed) | ||
<< !HasMessage << Msg.str() << AssertExpr->getSourceRange(); | ||
Diag(StaticAssertLoc, diag::err_static_assert_failed) | ||
<< !AssertMessage << Msg.str() << AssertExpr->getSourceRange(); | ||
Comment on lines
-17195
to
+17189
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This two lines are undoing the changes in:
|
||
PrintContextStack(); | ||
} | ||
Failed = true; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,6 +81,40 @@ 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}} | ||
} | ||
|
||
} | ||
|
||
|
||
Comment on lines
+84
to
+117
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same namespace exist in line 24 above, but that code includes modifications to the original test that are not part of this repeated section, like the ones introduced in 5ce5e98 which should avoid one of the failures we are experiencing in the tests. |
||
namespace dr2565 { // dr2565: 16 open | ||
#if __cplusplus >= 202002L | ||
template<typename T> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This bit is added in 47ccfd7 (https://reviews.llvm.org/D154290) on 2023-07-19, after the commit that is being double cherry-picked added the chunk of code below.