ChuanqiXu updated this revision to Diff 443123. ChuanqiXu added a comment. Minor changes.
CHANGES SINCE LAST ACTION https://reviews.llvm.org/D118034/new/ https://reviews.llvm.org/D118034 Files: clang/test/Modules/Inputs/redundant-template-default-arg/foo.cppm clang/test/Modules/Inputs/redundant-template-default-arg/foo.h clang/test/Modules/Inputs/redundant-template-default-arg2/foo.cppm clang/test/Modules/Inputs/redundant-template-default-arg3/foo.cppm clang/test/Modules/Inputs/redundant-template-default-arg3/foo.h clang/test/Modules/Inputs/redundant-template-default-arg3/foo_bad.h clang/test/Modules/fwd-declaration.cppm clang/test/Modules/redundant-template-default-arg.cpp clang/test/Modules/redundant-template-default-arg2.cpp clang/test/Modules/redundant-template-default-arg3.cpp
Index: clang/test/Modules/redundant-template-default-arg3.cpp =================================================================== --- clang/test/Modules/redundant-template-default-arg3.cpp +++ clang/test/Modules/redundant-template-default-arg3.cpp @@ -1,26 +1,113 @@ // RUN: rm -rf %t // RUN: mkdir %t -// RUN: %clang_cc1 -std=c++20 %S/Inputs/redundant-template-default-arg3/foo.cppm -I%S/Inputs/redundant-template-default-arg3/. -emit-module-interface -o %t/foo.pcm -// RUN: %clang_cc1 -fprebuilt-module-path=%t -std=c++20 %s -I%S/Inputs/redundant-template-default-arg3/. -fsyntax-only -verify +// RUN: split-file %s %t +// +// RUN: %clang_cc1 -std=c++20 %t/foo.cppm -I%t -emit-module-interface -o %t/foo.pcm +// RUN: %clang_cc1 -fprebuilt-module-path=%t -std=c++20 %t/use.cpp -I%t/. -fsyntax-only -verify +//--- foo.h +template <typename T = int> +T v; + +template <int T = 8> +int v2; + +template <typename T> +class my_array {}; + +template <template <typename> typename C = my_array> +int v3; + +template <typename T, int *i = nullptr> +T v4; + +template <typename T, T *i = nullptr> +T v5; + +inline int a = 43; +template <typename T, int *i = &a> +T v6; + +inline int b = 43; +template <typename T, T *i = &b> +T v7; + +template <int T = (3 > 2)> +int v8; + +consteval int getInt() { + return 55; +} +template <int T = getInt()> +int v9; + +//--- foo_bad.h +template <typename T = double> +T v; + +template <int T = 9> +int v2; + +template <typename T> +class others_array {}; + +template <template <typename> typename C = others_array> +int v3; + +static int a; +consteval int *getIntPtr() { + return &a; +} +template <typename T, int *i = getIntPtr()> +T v4; + +consteval void *getVoidPtr() { + return &a; +} +template <typename T, T *i = getVoidPtr()> +T v5; + +inline int a_ = 43; +template <typename T, int *i = &a_> +T v6; + +inline int b_ = 43; +template <typename T, T *i = &b_> +T v7; + +template <int T = -1> +int v8; + +consteval int getInt2() { + return 55; +} +template <int T = getInt2()> +int v9; + +//--- foo.cppm +module; +#include "foo.h" +export module foo; + +//--- use.cpp import foo; #include "foo_bad.h" -// expected-error@Inputs/redundant-template-default-arg3/foo_bad.h:1 {{template parameter default argument is inconsistent with previous definition}} -// expected-note@Inputs/redundant-template-default-arg3/foo.h:1 {{previous default template argument defined in module foo.<global>}} -// expected-error@Inputs/redundant-template-default-arg3/foo_bad.h:4 {{template parameter default argument is inconsistent with previous definition}} -// expected-note@Inputs/redundant-template-default-arg3/foo.h:4 {{previous default template argument defined in module foo.<global>}} -// expected-error@Inputs/redundant-template-default-arg3/foo_bad.h:10 {{template parameter default argument is inconsistent with previous definition}} -// expected-note@Inputs/redundant-template-default-arg3/foo.h:10 {{previous default template argument defined in module foo.<global>}} -// expected-error@Inputs/redundant-template-default-arg3/foo_bad.h:17 {{template parameter default argument is inconsistent with previous definition}} -// expected-note@Inputs/redundant-template-default-arg3/foo.h:13 {{previous default template argument defined in module foo.<global>}} -// expected-error@Inputs/redundant-template-default-arg3/foo_bad.h:23 {{template parameter default argument is inconsistent with previous definition}} -// expected-note@Inputs/redundant-template-default-arg3/foo.h:16 {{previous default template argument defined in module foo.<global>}} -// expected-error@Inputs/redundant-template-default-arg3/foo_bad.h:27 {{template parameter default argument is inconsistent with previous definition}} -// expected-note@Inputs/redundant-template-default-arg3/foo.h:20 {{previous default template argument defined in module foo.<global>}} -// expected-error@Inputs/redundant-template-default-arg3/foo_bad.h:31 {{template parameter default argument is inconsistent with previous definition}} -// expected-note@Inputs/redundant-template-default-arg3/foo.h:24 {{previous default template argument defined in module foo.<global>}} -// expected-error@Inputs/redundant-template-default-arg3/foo_bad.h:34 {{template parameter default argument is inconsistent with previous definition}} -// expected-note@Inputs/redundant-template-default-arg3/foo.h:27 {{previous default template argument defined in module foo.<global>}} -// expected-error@Inputs/redundant-template-default-arg3/foo_bad.h:40 {{template parameter default argument is inconsistent with previous definition}} -// expected-note@Inputs/redundant-template-default-arg3/foo.h:33 {{previous default template argument defined in module foo.<global>}} +// expected-error@foo_bad.h:1 {{template parameter default argument is inconsistent with previous definition}} +// expected-note@foo.h:1 {{previous default template argument defined in module foo.<global>}} +// expected-error@foo_bad.h:4 {{template parameter default argument is inconsistent with previous definition}} +// expected-note@foo.h:4 {{previous default template argument defined in module foo.<global>}} +// expected-error@foo_bad.h:10 {{template parameter default argument is inconsistent with previous definition}} +// expected-note@foo.h:10 {{previous default template argument defined in module foo.<global>}} +// expected-error@foo_bad.h:17 {{template parameter default argument is inconsistent with previous definition}} +// expected-note@foo.h:13 {{previous default template argument defined in module foo.<global>}} +// expected-error@foo_bad.h:23 {{template parameter default argument is inconsistent with previous definition}} +// expected-note@foo.h:16 {{previous default template argument defined in module foo.<global>}} +// expected-error@foo_bad.h:27 {{template parameter default argument is inconsistent with previous definition}} +// expected-note@foo.h:20 {{previous default template argument defined in module foo.<global>}} +// expected-error@foo_bad.h:31 {{template parameter default argument is inconsistent with previous definition}} +// expected-note@foo.h:24 {{previous default template argument defined in module foo.<global>}} +// expected-error@foo_bad.h:34 {{template parameter default argument is inconsistent with previous definition}} +// expected-note@foo.h:27 {{previous default template argument defined in module foo.<global>}} +// expected-error@foo_bad.h:40 {{template parameter default argument is inconsistent with previous definition}} +// expected-note@foo.h:33 {{previous default template argument defined in module foo.<global>}} Index: clang/test/Modules/redundant-template-default-arg2.cpp =================================================================== --- clang/test/Modules/redundant-template-default-arg2.cpp +++ clang/test/Modules/redundant-template-default-arg2.cpp @@ -1,20 +1,38 @@ // RUN: rm -rf %t // RUN: mkdir %t -// RUN: %clang_cc1 -std=c++20 %S/Inputs/redundant-template-default-arg2/foo.cppm -I%S/Inputs/redundant-template-default-arg2/. -emit-module-interface -o %t/foo.pcm -// RUN: %clang_cc1 -fprebuilt-module-path=%t -std=c++20 %s -fsyntax-only -verify +// RUN: split-file %s %t +// +// RUN: %clang_cc1 -std=c++20 %t/foo.cppm -I%t -emit-module-interface -o %t/foo.pcm +// RUN: %clang_cc1 -fprebuilt-module-path=%t -std=c++20 %t/use.cpp -fsyntax-only -verify + +//--- foo.cppm +export module foo; +export template <typename T = int> +T v; + +export template <int T = 8> +int v2; + +export template <typename T> +class my_array {}; + +export template <template <typename> typename C = my_array> +int v3; + +//--- use.cpp import foo; template <typename T = int> T v; // expected-error {{declaration of 'v' in the global module follows declaration in module foo}} - // expected-note@Inputs/redundant-template-default-arg2/foo.cppm:3 {{previous declaration is here}} + // expected-n...@foo.cppm:3 {{previous declaration is here}} template <int T = 8> int v2; // expected-error {{declaration of 'v2' in the global module follows declaration in module foo}} - // expected-note@Inputs/redundant-template-default-arg2/foo.cppm:6 {{previous declaration is here}} + // expected-n...@foo.cppm:6 {{previous declaration is here}} template <typename T> class my_array {}; // expected-error {{redefinition of 'my_array'}} - // expected-note@Inputs/redundant-template-default-arg2/foo.cppm:9 {{previous definition is here}} + // expected-n...@foo.cppm:9 {{previous definition is here}} template <template <typename> typename C = my_array> int v3; // expected-error {{declaration of 'v3' in the global module follows declaration in module foo}} - // expected-note@Inputs/redundant-template-default-arg2/foo.cppm:12 {{previous declaration is here}} + // expected-n...@foo.cppm:12 {{previous declaration is here}} Index: clang/test/Modules/redundant-template-default-arg.cpp =================================================================== --- clang/test/Modules/redundant-template-default-arg.cpp +++ clang/test/Modules/redundant-template-default-arg.cpp @@ -1,7 +1,56 @@ // RUN: rm -rf %t // RUN: mkdir %t -// RUN: %clang_cc1 -std=c++20 %S/Inputs/redundant-template-default-arg/foo.cppm -I%S/Inputs/redundant-template-default-arg/. -emit-module-interface -o %t/foo.pcm -// RUN: %clang_cc1 -fprebuilt-module-path=%t -std=c++20 %s -I%S/Inputs/redundant-template-default-arg/. -fsyntax-only -verify +// RUN: split-file %s %t +// +// RUN: %clang_cc1 -std=c++20 %t/foo.cppm -I%t -emit-module-interface -o %t/foo.pcm +// RUN: %clang_cc1 -fprebuilt-module-path=%t -std=c++20 %t/use.cpp -I%t -fsyntax-only -verify + +//--- foo.h +template <typename T> +T u; + +template <typename T = int> +T v; + +template <int T = 8> +int v2; + +template <typename T> +class my_array {}; + +template <template <typename> typename C = my_array> +int v3; + +template <typename T, int *i = nullptr> +T v4; + +template <typename T, T *i = nullptr> +T v5; + +inline int a = 43; +template <typename T, int *i = &a> +T v6; + +inline int b = 43; +template <typename T, T *i = &b> +T v7; + +template <int T = (3 > 2)> +int v8; + +consteval int getInt() { + return 55; +} +template <int T = getInt()> +int v9; + +//--- foo.cppm +module; +#include "foo.h" +export module foo; + + +//--- use.cpp // expected-no-diagnostics import foo; #include "foo.h" Index: clang/test/Modules/fwd-declaration.cppm =================================================================== --- /dev/null +++ clang/test/Modules/fwd-declaration.cppm @@ -0,0 +1,49 @@ +// RUN: rm -rf %t +// RUN: mkdir %t +// RUN: split-file %s %t +// +// RUN: %clang -std=c++20 --precompile %t/A.cppm -o %t/M-A.pcm +// RUN: %clang -std=c++20 --precompile %t/B.cppm -o %t/M-B.pcm +// RUN: %clang -std=c++20 --precompile %t/M.cppm -o %t/M.pcm -fprebuilt-module-path=%t +// RUN: %clang -std=c++20 -fprebuilt-module-path=%t %t/Use.cpp -S -o - +//--- fwd.h +template <class T> +class A; + +//--- impl.h +template <class T> +class A; +typedef A<int> a; +template <class T> +class A {}; + +template <> +class A<char> { +public: + A() {} + + A(int, double) {} +}; + +//--- A.cppm +module; +#include "fwd.h" +export module M:A; +export using ::A; + +//--- B.cppm +module; +#include "impl.h" +export module M:B; +export using ::A; + +//--- M.cppm +export module M; +export import :A; +export import :B; + +//--- Use.cpp +import M; +void use() { + A<int> a; +} Index: clang/test/Modules/Inputs/redundant-template-default-arg3/foo_bad.h =================================================================== --- clang/test/Modules/Inputs/redundant-template-default-arg3/foo_bad.h +++ /dev/null @@ -1,41 +0,0 @@ -template <typename T = double> -T v; - -template <int T = 9> -int v2; - -template <typename T> -class others_array {}; - -template <template <typename> typename C = others_array> -int v3; - -static int a; -consteval int *getIntPtr() { - return &a; -} -template <typename T, int *i = getIntPtr()> -T v4; - -consteval void *getVoidPtr() { - return &a; -} -template <typename T, T *i = getVoidPtr()> -T v5; - -inline int a_ = 43; -template <typename T, int *i = &a_> -T v6; - -inline int b_ = 43; -template <typename T, T *i = &b_> -T v7; - -template <int T = -1> -int v8; - -consteval int getInt2() { - return 55; -} -template <int T = getInt2()> -int v9; Index: clang/test/Modules/Inputs/redundant-template-default-arg3/foo.h =================================================================== --- clang/test/Modules/Inputs/redundant-template-default-arg3/foo.h +++ /dev/null @@ -1,34 +0,0 @@ -template <typename T = int> -T v; - -template <int T = 8> -int v2; - -template <typename T> -class my_array {}; - -template <template <typename> typename C = my_array> -int v3; - -template <typename T, int *i = nullptr> -T v4; - -template <typename T, T *i = nullptr> -T v5; - -inline int a = 43; -template <typename T, int *i = &a> -T v6; - -inline int b = 43; -template <typename T, T *i = &b> -T v7; - -template <int T = (3 > 2)> -int v8; - -consteval int getInt() { - return 55; -} -template <int T = getInt()> -int v9; Index: clang/test/Modules/Inputs/redundant-template-default-arg3/foo.cppm =================================================================== --- clang/test/Modules/Inputs/redundant-template-default-arg3/foo.cppm +++ /dev/null @@ -1,3 +0,0 @@ -module; -#include "foo.h" -export module foo; Index: clang/test/Modules/Inputs/redundant-template-default-arg2/foo.cppm =================================================================== --- clang/test/Modules/Inputs/redundant-template-default-arg2/foo.cppm +++ /dev/null @@ -1,12 +0,0 @@ -export module foo; -export template <typename T = int> -T v; - -export template <int T = 8> -int v2; - -export template <typename T> -class my_array {}; - -export template <template <typename> typename C = my_array> -int v3; Index: clang/test/Modules/Inputs/redundant-template-default-arg/foo.h =================================================================== --- clang/test/Modules/Inputs/redundant-template-default-arg/foo.h +++ /dev/null @@ -1,37 +0,0 @@ -template <typename T> -T u; - -template <typename T = int> -T v; - -template <int T = 8> -int v2; - -template <typename T> -class my_array {}; - -template <template <typename> typename C = my_array> -int v3; - -template <typename T, int *i = nullptr> -T v4; - -template <typename T, T *i = nullptr> -T v5; - -inline int a = 43; -template <typename T, int *i = &a> -T v6; - -inline int b = 43; -template <typename T, T *i = &b> -T v7; - -template <int T = (3 > 2)> -int v8; - -consteval int getInt() { - return 55; -} -template <int T = getInt()> -int v9; Index: clang/test/Modules/Inputs/redundant-template-default-arg/foo.cppm =================================================================== --- clang/test/Modules/Inputs/redundant-template-default-arg/foo.cppm +++ /dev/null @@ -1,3 +0,0 @@ -module; -#include "foo.h" -export module foo;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits