-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[clang][Interp] Fix diagnosing non-const variables pre-C++11 (#76718)
In CheckConstant(), consider that in C++98 const variables may not be read at all, and diagnose that accordingly.
- Loading branch information
Showing
3 changed files
with
89 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify=both,expected -std=c++11 %s | ||
// RUN: %clang_cc1 -verify=both,ref -std=c++11 %s | ||
|
||
// expected-no-diagnostics | ||
|
||
namespace IntOrEnum { | ||
const int k = 0; | ||
const int &p = k; | ||
template<int n> struct S {}; | ||
S<p> s; | ||
} | ||
|
||
const int cval = 2; | ||
template <int> struct C{}; | ||
template struct C<cval>; | ||
|
||
|
||
/// FIXME: This example does not get properly diagnosed in the new interpreter. | ||
extern const int recurse1; | ||
const int recurse2 = recurse1; // ref-note {{here}} | ||
const int recurse1 = 1; | ||
int array1[recurse1]; | ||
int array2[recurse2]; // ref-warning 2{{variable length array}} \ | ||
// ref-note {{initializer of 'recurse2' is not a constant expression}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify=both,expected -std=c++98 %s | ||
// RUN: %clang_cc1 -verify=both,ref -std=c++98 %s | ||
|
||
|
||
|
||
namespace IntOrEnum { | ||
const int k = 0; | ||
const int &p = k; // both-note {{declared here}} | ||
template<int n> struct S {}; | ||
S<p> s; // both-error {{not an integral constant expression}} \ | ||
// both-note {{read of variable 'p' of non-integral, non-enumeration type 'const int &'}} | ||
} | ||
|
||
const int cval = 2; | ||
template <int> struct C{}; | ||
template struct C<cval>; | ||
|
||
|
||
/// FIXME: This example does not get properly diagnosed in the new interpreter. | ||
extern const int recurse1; | ||
const int recurse2 = recurse1; // ref-note {{here}} | ||
const int recurse1 = 1; | ||
int array1[recurse1]; | ||
int array2[recurse2]; // ref-warning 2{{variable length array}} \ | ||
// ref-note {{initializer of 'recurse2' is not a constant expression}} \ | ||
// expected-warning {{variable length array}} \ | ||
// expected-error {{variable length array}} | ||
|
||
int NCI; // both-note {{declared here}} | ||
int NCIA[NCI]; // both-warning {{variable length array}} \ | ||
// both-error {{variable length array}} \\ | ||
// both-note {{read of non-const variable 'NCI'}} |