Clang Project

clang_source_code/test/Modules/merge-using-decls.cpp
1// RUN: rm -rf %t
2// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -x c++ -I%S/Inputs/merge-using-decls -verify %s -DORDER=1
3// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -x c++ -I%S/Inputs/merge-using-decls -verify -std=c++98 %s -DORDER=1
4// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -x c++ -I%S/Inputs/merge-using-decls -verify -std=c++11 %s -DORDER=1
5// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -x c++ -I%S/Inputs/merge-using-decls -verify %s -DORDER=2
6// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -x c++ -I%S/Inputs/merge-using-decls -verify -std=c++98 %s -DORDER=2
7// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -x c++ -I%S/Inputs/merge-using-decls -verify -std=c++11 %s -DORDER=2
8
9#if ORDER == 1
10#include "a.h"
11#include "b.h"
12#else
13#include "b.h"
14#include "a.h"
15#endif
16
17struct Y {
18  int value; // expected-note 0-1{{target of using}}
19  typedef int type; // expected-note 0-1{{target of using}}
20};
21
22template<typename T> int Use() {
23  int k = T().v + T().value; // expected-note 0-2{{instantiation of}}
24  typedef typename T::type I;
25  typedef typename T::t I;
26  typedef int I;
27  return k;
28}
29
30template<typename T> int UseAll() {
31#if __cplusplus <= 199711L // C++11 does not allow access declarations
32  return Use<C<T> >() + Use<D<T> >() + Use<E<T> >() + Use<F<T> >(); // expected-note 0-2{{instantiation of}}
33#else
34  return Use<C<T> >() + Use<D<T> >() + Use<F<T> >(); // expected-note 0-2{{instantiation of}}
35#endif
36}
37
38template int UseAll<YA>();
39template int UseAll<YB>();
40template int UseAll<Y>();
41
42// Which of these two sets of diagnostics is chosen is not important. It's OK
43// if this varies with ORDER, but it must be consistent across runs.
44#if ORDER == 1
45// Here, we're instantiating the definition from 'A' and merging the definition
46// from 'B' into it.
47
48#if __cplusplus <= 199711L // C++11 does not allow access declarations
49// expected-error@b.h:* {{'E::value' from module 'B' is not present in definition of 'E<T>' in module 'A'}}
50// expected-error@b.h:* {{'E::v' from module 'B' is not present in definition of 'E<T>' in module 'A'}}
51#endif
52
53// expected-error@b.h:* {{'F::type' from module 'B' is not present in definition of 'F<T>' in module 'A'}}
54// expected-error@b.h:* {{'F::t' from module 'B' is not present in definition of 'F<T>' in module 'A'}}
55// expected-error@b.h:* {{'F::value' from module 'B' is not present in definition of 'F<T>' in module 'A'}}
56// expected-error@b.h:* {{'F::v' from module 'B' is not present in definition of 'F<T>' in module 'A'}}
57
58// expected-note@a.h:* +{{does not match}}
59#else
60// Here, we're instantiating the definition from 'B' and merging the definition
61// from 'A' into it.
62
63// expected-error@a.h:* {{'D::type' from module 'A' is not present in definition of 'D<T>' in module 'B'}}
64// expected-error@a.h:* {{'D::value' from module 'A' is not present in definition of 'D<T>' in module 'B'}}
65// expected-error@b.h:* 2{{'typename' keyword used on a non-type}}
66// expected-error@b.h:* 2{{dependent using declaration resolved to type without 'typename'}}
67
68#if __cplusplus <= 199711L // C++11 does not allow access declarations
69// expected-error@a.h:* {{'E::type' from module 'A' is not present in definition of 'E<T>' in module 'B'}}
70// expected-error@a.h:* {{'E::t' from module 'A' is not present in definition of 'E<T>' in module 'B'}}
71// expected-error@a.h:* {{'E::value' from module 'A' is not present in definition of 'E<T>' in module 'B'}}
72// expected-error@a.h:* {{'E::v' from module 'A' is not present in definition of 'E<T>' in module 'B'}}
73// expected-note@b.h:* 2{{definition has no member}}
74#endif
75
76
77// expected-error@a.h:* {{'F::type' from module 'A' is not present in definition of 'F<T>' in module 'B'}}
78// expected-error@a.h:* {{'F::t' from module 'A' is not present in definition of 'F<T>' in module 'B'}}
79// expected-error@a.h:* {{'F::value' from module 'A' is not present in definition of 'F<T>' in module 'B'}}
80// expected-error@a.h:* {{'F::v' from module 'A' is not present in definition of 'F<T>' in module 'B'}}
81
82// expected-note@b.h:* +{{does not match}}
83// expected-note@b.h:* +{{target of using}}
84#endif
85