
Unlike C++, C allows the definition of an uninitialized `const` object. If the object has static or thread storage duration, it is still zero-initialized, otherwise, the object is left uninitialized. In either case, the code is not compatible with C++. This adds a new diagnostic group, `-Wdefault-const-init-unsafe`, which is on by default and diagnoses any definition of a `const` object which remains uninitialized. It also adds another new diagnostic group, `-Wdefault-const-init` (which also enabled the `unsafe` variant) that diagnoses any definition of a `const` object (including ones which are zero-initialized). This diagnostic is off by default. Finally, it adds `-Wdefault-const-init` to `-Wc++-compat`. GCC diagnoses these situations under this flag. Fixes #19297
12 lines
416 B
C
12 lines
416 B
C
// RUN: %clang_cc1 -fopenmp-simd -fsyntax-only -verify %s
|
|
// see https://github.com/llvm/llvm-project/issues/69069
|
|
// or https://github.com/llvm/llvm-project/pull/71480
|
|
|
|
void test() {
|
|
int v; const int x = 0; // expected-note {{variable 'x' declared const here}}
|
|
#pragma omp atomic capture
|
|
{
|
|
v = x;
|
|
x = 1; // expected-error {{cannot assign to variable 'x' with const-qualified type 'const int'}}
|
|
}
|
|
} |