Skip to content

Commit

Permalink
[clang][Interp] Only emit function_param_value_unknown in C++11 (#67990)
Browse files Browse the repository at this point in the history
This is also what the current interpreter does.
  • Loading branch information
tbaederr committed Oct 24, 2023
1 parent b44763c commit c45466c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
8 changes: 6 additions & 2 deletions clang/lib/AST/Interp/Interp.cpp
Expand Up @@ -555,8 +555,12 @@ bool CheckDeclRef(InterpState &S, CodePtr OpPC, const DeclRefExpr *DR) {
const SourceInfo &E = S.Current->getSource(OpPC);

if (isa<ParmVarDecl>(D)) {
S.FFDiag(E, diag::note_constexpr_function_param_value_unknown) << D;
S.Note(D->getLocation(), diag::note_declared_at) << D->getSourceRange();
if (S.getLangOpts().CPlusPlus11) {
S.FFDiag(E, diag::note_constexpr_function_param_value_unknown) << D;
S.Note(D->getLocation(), diag::note_declared_at) << D->getSourceRange();
} else {
S.FFDiag(E);
}
} else if (const auto *VD = dyn_cast<VarDecl>(D)) {
if (!VD->getType().isConstQualified()) {
S.FFDiag(E,
Expand Down
7 changes: 3 additions & 4 deletions clang/test/SemaCXX/offsetof.cpp
@@ -1,5 +1,5 @@
// RUN: %clang_cc1 -triple x86_64-apple-darwin10.0.0 -fsyntax-only -verify %s -Winvalid-offsetof -std=c++98
// RUN: %clang_cc1 -triple x86_64-apple-darwin10.0.0 -fsyntax-only -verify=expected,new-interp %s -Winvalid-offsetof -std=c++98 -fexperimental-new-constant-interpreter
// RUN: %clang_cc1 -triple x86_64-apple-darwin10.0.0 -fsyntax-only -verify %s -Winvalid-offsetof -std=c++98 -fexperimental-new-constant-interpreter

struct NonPOD {
virtual void f();
Expand All @@ -25,10 +25,9 @@ struct HasArray {
};

// Constant and non-constant offsetof expressions
void test_ice(int i) { // new-interp-note {{declared here}}
void test_ice(int i) {
int array0[__builtin_offsetof(HasArray, array[5])];
int array1[__builtin_offsetof(HasArray, array[i])]; // expected-warning {{variable length arrays in C++ are a Clang extension}} \
new-interp-note {{function parameter 'i' with unknown value cannot be used in a constant expression}}
int array1[__builtin_offsetof(HasArray, array[i])]; // expected-warning {{variable length arrays in C++ are a Clang extension}}
}

// Bitfields
Expand Down

0 comments on commit c45466c

Please sign in to comment.