From 6d9b84797c1c4bd00a2392043e9feea4ecebe482 Mon Sep 17 00:00:00 2001 From: Chuanqi Xu Date: Fri, 22 Jul 2022 17:03:38 +0800 Subject: [PATCH] [C++20] [Modules] Handle reachability for partial specialization Previously we don't catch the reachability for partial specialization. Handle them in this patch. --- clang/lib/Sema/SemaTemplate.cpp | 4 +-- .../test/Modules/partial_specialization.cppm | 34 +++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 clang/test/Modules/partial_specialization.cppm diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 171f005816b5..95c83ebfaeab 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -4573,7 +4573,7 @@ Sema::CheckVarTemplateId(VarTemplateDecl *Template, SourceLocation TemplateLoc, void *InsertPos = nullptr; if (VarTemplateSpecializationDecl *Spec = Template->findSpecialization( Converted, InsertPos)) { - checkSpecializationVisibility(TemplateNameLoc, Spec); + checkSpecializationReachability(TemplateNameLoc, Spec); // If we already have a variable template specialization, return it. return Spec; } @@ -4694,7 +4694,7 @@ Sema::CheckVarTemplateId(VarTemplateDecl *Template, SourceLocation TemplateLoc, dyn_cast(InstantiationPattern)) Decl->setInstantiationOf(D, InstantiationArgs); - checkSpecializationVisibility(TemplateNameLoc, Decl); + checkSpecializationReachability(TemplateNameLoc, Decl); assert(Decl && "No variable template specialization?"); return Decl; diff --git a/clang/test/Modules/partial_specialization.cppm b/clang/test/Modules/partial_specialization.cppm new file mode 100644 index 000000000000..3a0185717211 --- /dev/null +++ b/clang/test/Modules/partial_specialization.cppm @@ -0,0 +1,34 @@ +// RUN: rm -rf %t +// RUN: split-file %s %t +// RUN: cd %t +// +// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/A.cppm -o %t/A.pcm +// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/Use.cpp -fsyntax-only -verify +// +//--- foo.h +template +inline constexpr bool IsSame = false; + +template +inline constexpr bool IsSame = true; + +template +class A { +public: + A(); + ~A() noexcept(IsSame); +}; + +//--- A.cppm +module; +#include "foo.h" +export module A; +export using ::A; + +//--- Use.cpp +import A; +void bool_consume(bool b); +void use() { + A a{}; + bool_consume(IsSame); // expected-error {{use of undeclared identifier 'IsSame'}} +}