Author: yronglin Date: 2024-07-25T19:44:25+08:00 New Revision: 534e2dd29f252cc13b94312895d2f4b39b54b9d4
URL: https://github.com/llvm/llvm-project/commit/534e2dd29f252cc13b94312895d2f4b39b54b9d4 DIFF: https://github.com/llvm/llvm-project/commit/534e2dd29f252cc13b94312895d2f4b39b54b9d4.diff LOG: [Clang][Interp] Visit `DecompositionDecl` and create a local variable (#100400) The following code should be well-formed: ```C++ float decompose_complex(_Complex float cf) { static _Complex float scf; auto &[sre, sim] = scf; // ok, this is references initialized by constant expressions all the way down static_assert(&sre == &__real scf); static_assert(&sim == &__imag scf); auto [re, im] = cf; return re*re + im*im; } ``` We should visit `DecompositionDecl` and create a local variable but not a create a dummy value directly. --------- Signed-off-by: yronglin <yronglin...@gmail.com> Added: Modified: clang/lib/AST/Interp/Compiler.cpp clang/test/SemaCXX/cxx1z-decomposition.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/Interp/Compiler.cpp b/clang/lib/AST/Interp/Compiler.cpp index df55d01b8b9d6..11ca7f210d2d5 100644 --- a/clang/lib/AST/Interp/Compiler.cpp +++ b/clang/lib/AST/Interp/Compiler.cpp @@ -5239,6 +5239,10 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) { return false; }; + // DecompositionDecls are just proxies for us. + if (isa<DecompositionDecl>(VD)) + return revisit(VD); + // Visit local const variables like normal. if ((VD->hasGlobalStorage() || VD->isLocalVarDecl() || VD->isStaticDataMember()) && diff --git a/clang/test/SemaCXX/cxx1z-decomposition.cpp b/clang/test/SemaCXX/cxx1z-decomposition.cpp index 305a9ac2ebc24..19c730303625e 100644 --- a/clang/test/SemaCXX/cxx1z-decomposition.cpp +++ b/clang/test/SemaCXX/cxx1z-decomposition.cpp @@ -1,5 +1,6 @@ // RUN: %clang_cc1 -std=c++17 -Wc++20-extensions -verify=expected %s // RUN: %clang_cc1 -std=c++20 -Wpre-c++20-compat -verify=expected %s +// RUN: %clang_cc1 -std=c++20 -Wpre-c++20-compat -fexperimental-new-constant-interpreter -verify=expected %s void use_from_own_init() { auto [a] = a; // expected-error {{binding 'a' cannot appear in the initializer of its own decomposition declaration}} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits