xref: /llvm-project/clang/test/Modules/preferred_name.cppm (revision f21ead06750b670cf8ce72d6666e3550b04056a2)
1// Tests that the ODR check wouldn't produce false-positive result for preferred_name attribute.
2//
3// RUN: rm -rf %t
4// RUN: mkdir -p %t
5// RUN: split-file %s %t
6//
7// RUN: %clang_cc1 -std=c++20 %t/A.cppm -emit-module-interface -o %t/A.pcm
8// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t -I%t %t/Use.cppm -verify -fsyntax-only
9// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t -I%t %t/Use1.cpp -verify -fsyntax-only
10// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t -I%t %t/Use2.cpp -verify -fsyntax-only
11
12// Test again with reduced BMI.
13// RUN: rm -rf %t
14// RUN: mkdir -p %t
15// RUN: split-file %s %t
16//
17// RUN: %clang_cc1 -std=c++20 %t/A.cppm -emit-reduced-module-interface -o %t/A.pcm
18// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t -I%t %t/Use.cppm -verify -fsyntax-only
19// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t -I%t %t/Use1.cpp -verify -fsyntax-only
20// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t -I%t %t/Use2.cpp -verify -fsyntax-only
21//
22//--- foo.h
23template<class _CharT>
24class foo_templ;
25
26typedef foo_templ<char> foo;
27
28template<class _CharT>
29class
30__attribute__((__preferred_name__(foo)))
31foo_templ {
32public:
33    foo_templ() {}
34};
35
36inline foo_templ<char> bar()
37{
38  return foo_templ<char>();
39}
40
41//--- A.cppm
42module;
43#include "foo.h"
44export module A;
45export using ::foo_templ;
46
47//--- Use.cppm
48// expected-no-diagnostics
49module;
50#include "foo.h"
51export module Use;
52import A;
53export using ::foo_templ;
54
55//--- Use1.cpp
56import A;         // expected-warning@foo.h:8 {{attribute declaration must precede definition}}
57#include "foo.h"  // expected-note@foo.h:9 {{previous definition is here}}
58
59//--- Use2.cpp
60// expected-no-diagnostics
61#include "foo.h"
62import A;
63