================
@@ -1903,3 +1903,25 @@ namespace NonBlockPointerStore {
void foo(void) { a *= __builtin_sadd_overflow(1, 2, 0); }
void foo2(void) { a *= __builtin_addc(1, 2, 0, 0); }
}
+
+namespace WcslenInvalidArg {
+
+ // 1) Narrow string literal passed to wcslen builtin: hard error in C++.
+ static_assert(__builtin_wcslen("x") == 'x');
+ // both-error@-1 {{cannot initialize a parameter of type 'const wchar_t *'
with an lvalue of type 'const char[2]'}}
+
+ // 2) Forced cast: should not crash, but not a constant expression.
+ static_assert(__builtin_wcslen((const wchar_t *)"x") == 1);
+ // both-error@-1 {{static assertion expression is not an integral constant
expression}}
+ // both-note@-2 {{cast that performs the conversions of a reinterpret_cast}}
----------------
tbaederr wrote:
```suggestion
static_assert(__builtin_wcslen((const wchar_t *)"x") == 1); // both-error
{{static assertion expression is not an integral constant expression}} \
// both-note {{cast that performs the conversions of a
reinterpret_cast}}
```
Add the expected output at the end of the line, like the rest of this file does.
https://github.com/llvm/llvm-project/pull/177891
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits