diff --git a/interpreter/cling/lib/Interpreter/DefinitionShadower.cpp b/interpreter/cling/lib/Interpreter/DefinitionShadower.cpp index 0f2ba28cc9401..5f9685be66de6 100644 --- a/interpreter/cling/lib/Interpreter/DefinitionShadower.cpp +++ b/interpreter/cling/lib/Interpreter/DefinitionShadower.cpp @@ -35,7 +35,9 @@ namespace cling { && (SM.getFileID(SM.getIncludeLoc(FID)) == SM.getMainFileID()); } - /// \brief Returns whether the given {Function,Tag,Var}Decl/TemplateDecl is a definition. + /// \brief Returns whether a declaration is a definition. A `TemplateDecl` is + /// a definition if the templated decl is itself a definition; a concept is + /// always considered a definition. static bool isDefinition(const Decl *D) { if (auto FD = dyn_cast(D)) return FD->isThisDeclarationADefinition(); @@ -44,7 +46,7 @@ namespace cling { if (auto VD = dyn_cast(D)) return VD->isThisDeclarationADefinition(); if (auto TD = dyn_cast(D)) - return isDefinition(TD->getTemplatedDecl()); + return isa(TD) || isDefinition(TD->getTemplatedDecl()); return true; } diff --git a/interpreter/cling/test/CodeUnloading/DeclShadowing.C b/interpreter/cling/test/CodeUnloading/DeclShadowing.C index 4b7b54d6f4532..01b79739ddb89 100644 --- a/interpreter/cling/test/CodeUnloading/DeclShadowing.C +++ b/interpreter/cling/test/CodeUnloading/DeclShadowing.C @@ -6,14 +6,17 @@ // LICENSE.TXT for details. //------------------------------------------------------------------------------ -// RUN: cat %s | %cling 2>&1 | FileCheck %s +// RUN: cat %s | %cling 2>&1 | FileCheck --implicit-check-not error: %s #include "cling/Interpreter/Interpreter.h" #include "cling/Utils/AST.h" #include "clang/AST/Decl.h" -#include +#if __cplusplus > 202002L +#include +#endif #include #include +#include unsigned _i; struct _X {}; @@ -98,6 +101,18 @@ f(33) f(3.3f) //CHECK-NEXT: (int) 21930 +#if __cplusplus > 202002L +template +concept IsIntegral = false; + +// Replace concept definition; no error is expected in `constrained_fn(10)` below +template +concept IsIntegral = std::is_integral::value; + +void constrained_fn(IsIntegral auto x) {} +void g() { constrained_fn(10); } +#endif + cling::runtime::gClingOpts->AllowRedefinition = 0; // ==== Check DeclContext