Skip to content

Commit eaea4d1

Browse files
authored
[clang] The ms-extension __noop should return zero in a constexpr context. (#106849)
Fixes #106713.
1 parent cde3838 commit eaea4d1

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

clang/lib/AST/ExprConstant.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12720,8 +12720,8 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
1272012720
}
1272112721

1272212722
case Builtin::BI__noop:
12723-
// __noop always evaluates successfully
12724-
return true;
12723+
// __noop always evaluates successfully and returns 0.
12724+
return Success(0, E);
1272512725

1272612726
case Builtin::BI__builtin_is_constant_evaluated: {
1272712727
const auto *Callee = Info.CurrentCall->getCallee();

clang/test/SemaCXX/builtins.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,5 +177,21 @@ static void __builtin_cpu_init(); // expected-error {{static declaration of '__b
177177
#endif
178178

179179
#ifdef _MSC_VER
180-
constexpr int x = []{ __noop; return 0; }(); // expected-no-diagnostics
180+
constexpr int x = [] {
181+
__noop;
182+
return 0;
183+
}(); // expected-no-diagnostics
184+
static_assert([] { return __noop; }() == 0);
185+
static_assert([] { return __noop(4); }() == 0);
186+
extern int not_accessed;
187+
void not_called();
188+
static_assert([] { return __noop(not_accessed *= 6); }() == 0);
189+
static_assert([] { return __noop(not_called()); }() == 0);
190+
static_assert([] { return __noop(throw ""); }() == 0);
191+
static_assert([] { return __noop(throw "", throw ""); }() == 0);
192+
static_assert([] {
193+
int a = 5;
194+
__noop(++a);
195+
return a;
196+
}() == 5);
181197
#endif

0 commit comments

Comments
 (0)