Files
clang-p2996/clang/test/Parser/cxx23-assume.cpp
Sirraide 2b5f68a5f6 [Clang][C++23] Implement P1774R8: Portable assumptions (#81014)
This implements the C++23 `[[assume]]` attribute.

Assumption information is lowered to a call to `@llvm.assume`, unless the expression has side-effects, in which case it is discarded and a warning is issued to tell the user that the assumption doesn’t do anything. A failed assumption at compile time is an error (unless we are in `MSVCCompat` mode, in which case we don’t check assumptions at compile time).

Due to performance regressions in LLVM, assumptions can be disabled with the `-fno-assumptions` flag. With it, assumptions will still be parsed and checked, but no calls to `@llvm.assume` will be emitted and assumptions will not be checked at compile time.
2024-03-09 12:07:16 +01:00

19 lines
660 B
C++

// RUN: %clang_cc1 -std=c++23 -x c++ %s -verify
void f(int x, int y) {
[[assume(true)]];
[[assume(1)]];
[[assume(1.0)]];
[[assume(1 + 2 == 3)]];
[[assume(x ? 1 : 2)]];
[[assume(x && y)]];
[[assume(true)]] [[assume(true)]];
[[assume]]; // expected-error {{takes one argument}}
[[assume(]]; // expected-error {{expected expression}}
[[assume()]]; // expected-error {{expected expression}}
[[assume(2]]; // expected-error {{expected ')'}} expected-note {{to match this '('}}
[[assume(x = 2)]]; // expected-error {{requires parentheses}}
[[assume(2, 3)]]; // expected-error {{requires parentheses}} expected-warning {{has no effect}}
}