Skip to content

Commit

Permalink
[clang] The ms-extension __noop should return zero in a constexpr con…
Browse files Browse the repository at this point in the history
…text. (llvm#106849)

Fixes llvm#106713.
  • Loading branch information
c8ef authored Sep 2, 2024
1 parent cde3838 commit eaea4d1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
4 changes: 2 additions & 2 deletions clang/lib/AST/ExprConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12720,8 +12720,8 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
}

case Builtin::BI__noop:
// __noop always evaluates successfully
return true;
// __noop always evaluates successfully and returns 0.
return Success(0, E);

case Builtin::BI__builtin_is_constant_evaluated: {
const auto *Callee = Info.CurrentCall->getCallee();
Expand Down
18 changes: 17 additions & 1 deletion clang/test/SemaCXX/builtins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,21 @@ static void __builtin_cpu_init(); // expected-error {{static declaration of '__b
#endif

#ifdef _MSC_VER
constexpr int x = []{ __noop; return 0; }(); // expected-no-diagnostics
constexpr int x = [] {
__noop;
return 0;
}(); // expected-no-diagnostics
static_assert([] { return __noop; }() == 0);
static_assert([] { return __noop(4); }() == 0);
extern int not_accessed;
void not_called();
static_assert([] { return __noop(not_accessed *= 6); }() == 0);
static_assert([] { return __noop(not_called()); }() == 0);
static_assert([] { return __noop(throw ""); }() == 0);
static_assert([] { return __noop(throw "", throw ""); }() == 0);
static_assert([] {
int a = 5;
__noop(++a);
return a;
}() == 5);
#endif

0 comments on commit eaea4d1

Please sign in to comment.