Skip to content

[[assume(++a)]] warns that the side-effects will be discarded, but they are not discarded at compile time #85519

Closed
@tbaederr

Description

@tbaederr
constexpr int a() {
  int a = 0;
  [[assume(++a)]];
  return a;
}
static_assert(a() == 1);

#include <iostream>

int main() {
  std::cout << a() << "\n";
}

This code prints 0, even though the static_assert doesn't fail. Clang does print a warning about the side-effects of ++a being discarded, but that is not true at compile time.

CC @Sirraide

Metadata

Metadata

Assignees

Labels

clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerclang:frontendLanguage frontend issues, e.g. anything involving "Sema"constexprAnything related to constant evaluation

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions