Author: Chuanqi Xu Date: 2023-07-11T15:59:03+08:00 New Revision: f82df0b285acd8a7115f0bfc55ce44474251c2d1
URL: https://github.com/llvm/llvm-project/commit/f82df0b285acd8a7115f0bfc55ce44474251c2d1 DIFF: https://github.com/llvm/llvm-project/commit/f82df0b285acd8a7115f0bfc55ce44474251c2d1.diff LOG: [C++20] [Modules] Use CanonicalType for base classes This comes from https://reviews.llvm.org/D153003 By @rsmith, the test case is valid since: > Per [temp.type]/1.4 (http://eel.is/c++draft/temp.type#1.4), > >> Two template-ids are the same if [...] their corresponding template >> template-arguments refer to the same template. > so B<A> and B<NS::A> are the same type. The stricter "same sequence of > tokens" rule doesn't apply here, because using-declarations are not > definitions. > we should either (preferably) be including only the syntactic form of > the base specifier (because local syntax is what the ODR covers), or > the canonical type (which should be the same for both > using-declarations). Here we adopt the second suggested solutions. Reviewed By: cor3ntin, v.g.vassilev Differential Revision: https://reviews.llvm.org/D154324 Added: clang/test/Modules/pr63595.cppm Modified: clang/lib/AST/ODRHash.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/ODRHash.cpp b/clang/lib/AST/ODRHash.cpp index 507fb0b49f8ad3..40d68a310dd2a8 100644 --- a/clang/lib/AST/ODRHash.cpp +++ b/clang/lib/AST/ODRHash.cpp @@ -593,7 +593,7 @@ void ODRHash::AddCXXRecordDecl(const CXXRecordDecl *Record) { ID.AddInteger(Record->getNumBases()); auto Bases = Record->bases(); for (const auto &Base : Bases) { - AddQualType(Base.getType()); + AddQualType(Base.getType().getCanonicalType()); ID.AddInteger(Base.isVirtual()); ID.AddInteger(Base.getAccessSpecifierAsWritten()); } diff --git a/clang/test/Modules/pr63595.cppm b/clang/test/Modules/pr63595.cppm new file mode 100644 index 00000000000000..f2caf629ac10b8 --- /dev/null +++ b/clang/test/Modules/pr63595.cppm @@ -0,0 +1,44 @@ +// RUN: rm -rf %t +// RUN: mkdir %t +// RUN: split-file %s %t +// +// RUN: %clang_cc1 -std=c++20 -emit-module-interface -I%t %t/module1.cppm -o %t/module1.pcm +// RUN: %clang_cc1 -std=c++20 -emit-module-interface -I%t %t/module2.cppm -o %t/module2.pcm +// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/merge.cpp -verify -fsyntax-only + +//--- header.h +namespace NS { +template <int I> +class A { +}; + +template <template <int I_> class T> +class B { +}; +} + +//--- module1.cppm +// inside NS, using C = B<A> +module; +export module module1; +#include "header.h" +namespace NS { +using C = B<A>; +} +export struct D : NS::C {}; + +//--- module2.cppm +// inside NS, using C = B<NS::A> +module; +export module module2; +#include "header.h" +namespace NS { +using C = B<NS::A>; +} +export struct D : NS::C {}; + +//--- merge.cpp +// expected-no-diagnostics +import module1; +import module2; +D d; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits