Index: clang/lib/Sema/SemaDecl.cpp =================================================================== --- clang/lib/Sema/SemaDecl.cpp +++ clang/lib/Sema/SemaDecl.cpp @@ -1821,17 +1821,20 @@ return OldM == NewM; } -static bool isUsingDecl(NamedDecl *D) { +static bool isUsingDeclAtClassScope(NamedDecl *D) { + if (D->getDeclContext()->isFileContext()) + return false; + return isa(D) || isa(D) || isa(D); } -/// Removes using shadow declarations from the lookup results. +/// Removes using shadow declarations at class scope from the lookup results. static void RemoveUsingDecls(LookupResult &R) { LookupResult::Filter F = R.makeFilter(); while (F.hasNext()) - if (isUsingDecl(F.next())) + if (isUsingDeclAtClassScope(F.next())) F.erase(); F.done(); @@ -6378,10 +6381,6 @@ // containing the two f's declared in X, but neither of them // matches. - // C++ [dcl.meaning]p1: - // [...] the member shall not merely have been introduced by a - // using-declaration in the scope of the class or namespace nominated by - // the nested-name-specifier of the declarator-id. RemoveUsingDecls(Previous); } Index: clang/test/Modules/pr62158.cppm =================================================================== --- /dev/null +++ clang/test/Modules/pr62158.cppm @@ -0,0 +1,46 @@ +// RUN: rm -rf %t +// RUN: mkdir -p %t +// RUN: split-file %s %t +// +// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/lib.cppm -o %t/lib.pcm +// RUN: %clang_cc1 -std=c++20 %t/main.cpp -fmodule-file=lib=%t/lib.pcm \ +// RUN: -verify -fsyntax-only + +//--- header.h +namespace lib::inline __1 { +template +inline constexpr bool test = false; +template +constexpr bool func() { + return false; +} +inline constexpr bool non_templ = true; +} // namespace lib + +//--- lib.cppm +module; +#include "header.h" +export module lib; + +export namespace lib { + using lib::test; + using lib::func; + using lib::non_templ; +} // namespace lib + +//--- main.cpp +// expected-no-diagnostics +import lib; + +struct foo {}; + +template <> +inline constexpr bool lib::test = true; + +template <> +constexpr bool lib::func() { + return true; +} + +static_assert(lib::test); +static_assert(lib::func()); Index: clang/test/SemaCXX/pr62174.cpp =================================================================== --- /dev/null +++ clang/test/SemaCXX/pr62174.cpp @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -std=c++20 %s -fsyntax-only -verify +// expected-no-diagnostics +namespace lib { + namespace impl { + template + inline constexpr bool test = false; + } + using impl::test; +} + +struct foo {}; + +template <> +inline constexpr bool lib::test = true; + +static_assert(lib::test);