181c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com// RUN: rm -rf %t
281c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -x c++ -I%S/Inputs/merge-using-decls -verify %s -DORDER=1
381c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -x c++ -I%S/Inputs/merge-using-decls -verify %s -DORDER=2
481c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com
581c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com#if ORDER == 1
681c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com#include "a.h"
781c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com#include "b.h"
881c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com#else
981c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com#include "b.h"
108dc7c3a839b38b73af34cc2674a06f49eb1ce527egdaniel#include "a.h"
118dc7c3a839b38b73af34cc2674a06f49eb1ce527egdaniel#endif
1281c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com
1344701df5ce572ac3cccec785cf52103d3d5d14a5joshualittstruct Y {
146d3fe022d68fd6dd32c0fab30e24fa5a4f048946bsalomon  int value; // expected-note 0-1{{target of using}}
1581c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com  typedef int type; // expected-note 0-1{{target of using}}
16558a75bcb323c03dd7482555c7214062a363276fbsalomon@google.com};
1746a8600405e678718271f62c5994119b8d3241e9robertphillips@google.com
18558a75bcb323c03dd7482555c7214062a363276fbsalomon@google.comtemplate<typename T> int Use() {
198dc7c3a839b38b73af34cc2674a06f49eb1ce527egdaniel  int k = T().v + T().value; // expected-note 0-2{{instantiation of}}
2081c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com  typedef typename T::type I;
212766c00fc0b6a07d46e5f74cdad45da2ef625237mtklein  typedef typename T::t I;
2246a8600405e678718271f62c5994119b8d3241e9robertphillips@google.com  typedef int I;
238dc7c3a839b38b73af34cc2674a06f49eb1ce527egdaniel  return k;
24558a75bcb323c03dd7482555c7214062a363276fbsalomon@google.com}
25558a75bcb323c03dd7482555c7214062a363276fbsalomon@google.com
26558a75bcb323c03dd7482555c7214062a363276fbsalomon@google.comtemplate<typename T> int UseAll() {
2781c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com  return Use<C<T> >() + Use<D<T> >() + Use<E<T> >() + Use<F<T> >(); // expected-note 0-2{{instantiation of}}
2881c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com}
2981c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com
30558a75bcb323c03dd7482555c7214062a363276fbsalomon@google.comtemplate int UseAll<YA>();
3181c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.comtemplate int UseAll<YB>();
3281c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.comtemplate int UseAll<Y>();
334c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com
344c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com// Which of these two sets of diagnostics is chosen is not important. It's OK
354c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com// if this varies with ORDER, but it must be consistent across runs.
364c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com#if ORDER == 1
374c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com// Here, we're instantiating the definition from 'A' and merging the definition
384c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com// from 'B' into it.
3981c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com
4081c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com// expected-error@b.h:* {{'E::value' from module 'B' is not present in definition of 'E<T>' in module 'A'}}
4181c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com// expected-error@b.h:* {{'E::v' from module 'B' is not present in definition of 'E<T>' in module 'A'}}
424c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com
434c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com// expected-error@b.h:* {{'F::type' from module 'B' is not present in definition of 'F<T>' in module 'A'}}
444c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com// expected-error@b.h:* {{'F::t' from module 'B' is not present in definition of 'F<T>' in module 'A'}}
45d3e5842db0cb169e10d6da1e62c94ba5cf182bb4commit-bot@chromium.org// expected-error@b.h:* {{'F::value' from module 'B' is not present in definition of 'F<T>' in module 'A'}}
464c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com// expected-error@b.h:* {{'F::v' from module 'B' is not present in definition of 'F<T>' in module 'A'}}
474c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com
4881c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com// expected-note@a.h:* +{{does not match}}
4981c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com#else
5002a44a488605112aa6683c9d919e13b188112ce1bsalomon// Here, we're instantiating the definition from 'B' and merging the definition
5102a44a488605112aa6683c9d919e13b188112ce1bsalomon// from 'A' into it.
528dc7c3a839b38b73af34cc2674a06f49eb1ce527egdaniel
538dc7c3a839b38b73af34cc2674a06f49eb1ce527egdaniel// expected-error@a.h:* {{'D::type' from module 'A' is not present in definition of 'D<T>' in module 'B'}}
5446a8600405e678718271f62c5994119b8d3241e9robertphillips@google.com// expected-error@a.h:* {{'D::value' from module 'A' is not present in definition of 'D<T>' in module 'B'}}
5581c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com// expected-error@b.h:* 2{{'typename' keyword used on a non-type}}
568dc7c3a839b38b73af34cc2674a06f49eb1ce527egdaniel// expected-error@b.h:* 2{{dependent using declaration resolved to type without 'typename'}}
578dc7c3a839b38b73af34cc2674a06f49eb1ce527egdaniel
5836c57dfb4fe9bbaca436942d5eaa75b142ba251dkkinnunen// expected-error@a.h:* {{'E::type' from module 'A' is not present in definition of 'E<T>' in module 'B'}}
5981c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com// expected-error@a.h:* {{'E::t' from module 'A' is not present in definition of 'E<T>' in module 'B'}}
6081c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com// expected-error@a.h:* {{'E::value' from module 'A' is not present in definition of 'E<T>' in module 'B'}}
6181c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com// expected-error@a.h:* {{'E::v' from module 'A' is not present in definition of 'E<T>' in module 'B'}}
62558a75bcb323c03dd7482555c7214062a363276fbsalomon@google.com// expected-note@b.h:* 2{{definition has no member}}
634c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com
644c2443e36fdc6c095b17e90baa4a2f26a6f00b08bsalomon@google.com// expected-error@a.h:* {{'F::type' from module 'A' is not present in definition of 'F<T>' in module 'B'}}
6581c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com// expected-error@a.h:* {{'F::t' from module 'A' is not present in definition of 'F<T>' in module 'B'}}
6681c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com// expected-error@a.h:* {{'F::value' from module 'A' is not present in definition of 'F<T>' in module 'B'}}
6781c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com// expected-error@a.h:* {{'F::v' from module 'A' is not present in definition of 'F<T>' in module 'B'}}
68eefe6f1eef1b5cd394853a3f31a92c3c8db62c45bsalomon@google.com
6981c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com// expected-note@b.h:* +{{does not match}}
7081c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com// expected-note@b.h:* +{{target of using}}
7181c3f8de1cbb93a8b99d730a75ab16d864612e95bsalomon@google.com#endif
72558a75bcb323c03dd7482555c7214062a363276fbsalomon@google.com