Skip to content

Commit 3716b8c

Browse files
committed
Revert "Merge pull request #9200 from compnerd/static_assert_false"
This reverts commit 4857f75, reversing changes made to fe0f467. This reverts PR #9200. The cherry-pick that's being tried in that PR is already part of the branch (00e2098), and the commit removes code added after the original commit, and duplicates some testing code, producing errors in several tests. See the comments of #9200 for more details.
1 parent 03098d4 commit 3716b8c

File tree

2 files changed

+10
-37
lines changed

2 files changed

+10
-37
lines changed

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17146,14 +17146,21 @@ Decl *Sema::BuildStaticAssertDeclaration(SourceLocation StaticAssertLoc,
1714617146
FoldKind).isInvalid())
1714717147
Failed = true;
1714817148

17149+
// If the static_assert passes, only verify that
17150+
// the message is grammatically valid without evaluating it.
17151+
if (!Failed && AssertMessage && Cond.getBoolValue()) {
17152+
std::string Str;
17153+
EvaluateStaticAssertMessageAsString(AssertMessage, Str, Context,
17154+
/*ErrorOnInvalidMessage=*/false);
17155+
}
17156+
1714917157
// CWG2518
1715017158
// [dcl.pre]/p10 If [...] the expression is evaluated in the context of a
1715117159
// template definition, the declaration has no effect.
1715217160
bool InTemplateDefinition =
1715317161
getLangOpts().CPlusPlus && CurContext->isDependentContext();
1715417162

1715517163
if (!Failed && !Cond && !InTemplateDefinition) {
17156-
1715717164
SmallString<256> MsgBuffer;
1715817165
llvm::raw_svector_ostream Msg(MsgBuffer);
1715917166
bool HasMessage = AssertMessage;
@@ -17185,8 +17192,8 @@ Decl *Sema::BuildStaticAssertDeclaration(SourceLocation StaticAssertLoc,
1718517192
<< InnerCond->getSourceRange();
1718617193
DiagnoseStaticAssertDetails(InnerCond);
1718717194
} else {
17188-
Diag(StaticAssertLoc, diag::err_static_assert_failed)
17189-
<< !AssertMessage << Msg.str() << AssertExpr->getSourceRange();
17195+
Diag(AssertExpr->getBeginLoc(), diag::err_static_assert_failed)
17196+
<< !HasMessage << Msg.str() << AssertExpr->getSourceRange();
1719017197
PrintContextStack();
1719117198
}
1719217199
Failed = true;

clang/test/CXX/drs/dr25xx.cpp

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -81,40 +81,6 @@ using ::dr2521::operator""_div;
8181
#endif
8282
} // namespace dr2521
8383

84-
namespace dr2518 { // dr2518: 17 review
85-
86-
template <class T>
87-
void f(T t) {
88-
if constexpr (sizeof(T) != sizeof(int)) {
89-
static_assert(false, "must be int-sized"); // expected-error {{must be int-size}}
90-
}
91-
}
92-
93-
void g(char c) {
94-
f(0);
95-
f(c); // expected-note {{requested here}}
96-
}
97-
98-
template <typename Ty>
99-
struct S {
100-
static_assert(false); // expected-error {{static assertion failed}}
101-
};
102-
103-
template <>
104-
struct S<int> {};
105-
106-
template <>
107-
struct S<float> {};
108-
109-
int test_specialization() {
110-
S<int> s1;
111-
S<float> s2;
112-
S<double> s3; // expected-note {{in instantiation of template class 'dr2518::S<double>' requested here}}
113-
}
114-
115-
}
116-
117-
11884
namespace dr2565 { // dr2565: 16 open
11985
#if __cplusplus >= 202002L
12086
template<typename T>

0 commit comments

Comments
 (0)