xref: /aosp_15_r20/external/clang/test/SemaCXX/cxx98-compat-flags.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wc++98-compat-pedantic -verify %s
2*67e74705SXin Li // RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wc++98-compat-pedantic -Wno-bind-to-temporary-copy -Wno-unnamed-type-template-args -Wno-local-type-template-args -Werror %s
3*67e74705SXin Li 
TemplateFn(T)4*67e74705SXin Li template<typename T> int TemplateFn(T) { return 0; }
LocalTemplateArg()5*67e74705SXin Li void LocalTemplateArg() {
6*67e74705SXin Li   struct S {};
7*67e74705SXin Li   TemplateFn(S()); // expected-warning {{local type 'S' as template argument is incompatible with C++98}}
8*67e74705SXin Li }
9*67e74705SXin Li struct {} obj_of_unnamed_type; // expected-note {{here}}
10*67e74705SXin Li int UnnamedTemplateArg = TemplateFn(obj_of_unnamed_type); // expected-warning {{unnamed type as template argument is incompatible with C++98}}
11*67e74705SXin Li 
12*67e74705SXin Li namespace CopyCtorIssues {
13*67e74705SXin Li   struct Private {
14*67e74705SXin Li     Private();
15*67e74705SXin Li   private:
16*67e74705SXin Li     Private(const Private&); // expected-note {{declared private here}}
17*67e74705SXin Li   };
18*67e74705SXin Li   struct NoViable {
19*67e74705SXin Li     NoViable();
20*67e74705SXin Li     NoViable(NoViable&); // expected-note {{not viable}}
21*67e74705SXin Li   };
22*67e74705SXin Li   struct Ambiguous {
23*67e74705SXin Li     Ambiguous();
24*67e74705SXin Li     Ambiguous(const Ambiguous &, int = 0); // expected-note {{candidate}}
25*67e74705SXin Li     Ambiguous(const Ambiguous &, double = 0); // expected-note {{candidate}}
26*67e74705SXin Li   };
27*67e74705SXin Li   struct Deleted {
28*67e74705SXin Li     Private p; // expected-note {{copy constructor of 'Deleted' is implicitly deleted because field 'p' has an inaccessible copy constructor}}
29*67e74705SXin Li   };
30*67e74705SXin Li 
31*67e74705SXin Li   const Private &a = Private(); // expected-warning {{copying variable of type 'CopyCtorIssues::Private' when binding a reference to a temporary would invoke an inaccessible constructor in C++98}}
32*67e74705SXin Li   const NoViable &b = NoViable(); // expected-warning {{copying variable of type 'CopyCtorIssues::NoViable' when binding a reference to a temporary would find no viable constructor in C++98}}
33*67e74705SXin Li   const Ambiguous &c = Ambiguous(); // expected-warning {{copying variable of type 'CopyCtorIssues::Ambiguous' when binding a reference to a temporary would find ambiguous constructors in C++98}}
34*67e74705SXin Li   const Deleted &d = Deleted(); // expected-warning {{copying variable of type 'CopyCtorIssues::Deleted' when binding a reference to a temporary would invoke a deleted constructor in C++98}}
35*67e74705SXin Li }
36