xref: /minix3/external/bsd/llvm/dist/clang/test/SemaCXX/warn-large-by-value-copy.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -verify -fsyntax-only -Wlarge-by-value-copy=100 %s
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc // rdar://8548050
4*f4a2713aSLionel Sambuc namespace rdar8548050 {
5*f4a2713aSLionel Sambuc 
6*f4a2713aSLionel Sambuc struct S100 {
7*f4a2713aSLionel Sambuc     char x[100];
8*f4a2713aSLionel Sambuc };
9*f4a2713aSLionel Sambuc 
10*f4a2713aSLionel Sambuc struct S101 {
11*f4a2713aSLionel Sambuc     char x[101];
12*f4a2713aSLionel Sambuc };
13*f4a2713aSLionel Sambuc 
f100(S100 s)14*f4a2713aSLionel Sambuc S100 f100(S100 s) { return s; }
15*f4a2713aSLionel Sambuc 
f101(S101 s)16*f4a2713aSLionel Sambuc S101 f101(S101 s) { return s; } // expected-warning {{return value of 'f101' is a large (101 bytes) pass-by-value object}} \
17*f4a2713aSLionel Sambuc                                 // expected-warning {{'s' is a large (101 bytes) pass-by-value argument}}
18*f4a2713aSLionel Sambuc 
19*f4a2713aSLionel Sambuc typedef int Arr[200];
farr(Arr a)20*f4a2713aSLionel Sambuc void farr(Arr a) { }
21*f4a2713aSLionel Sambuc 
22*f4a2713aSLionel Sambuc struct NonPOD {
23*f4a2713aSLionel Sambuc   char x[200];
24*f4a2713aSLionel Sambuc   virtual void m();
25*f4a2713aSLionel Sambuc };
26*f4a2713aSLionel Sambuc 
fNonPOD(NonPOD s)27*f4a2713aSLionel Sambuc NonPOD fNonPOD(NonPOD s) { return s; }
28*f4a2713aSLionel Sambuc 
29*f4a2713aSLionel Sambuc template <unsigned size>
30*f4a2713aSLionel Sambuc struct TS {
31*f4a2713aSLionel Sambuc     char x[size];
32*f4a2713aSLionel Sambuc };
33*f4a2713aSLionel Sambuc 
34*f4a2713aSLionel Sambuc template <unsigned size>
tf(TS<size> ts)35*f4a2713aSLionel Sambuc void tf(TS<size> ts) {} // expected-warning {{ts' is a large (300 bytes) pass-by-value argument}}
36*f4a2713aSLionel Sambuc 
g()37*f4a2713aSLionel Sambuc void g() {
38*f4a2713aSLionel Sambuc     TS<300> ts;
39*f4a2713aSLionel Sambuc     tf<300>(ts); // expected-note {{instantiation}}
40*f4a2713aSLionel Sambuc }
41*f4a2713aSLionel Sambuc 
42*f4a2713aSLionel Sambuc }
43*f4a2713aSLionel Sambuc 
44*f4a2713aSLionel Sambuc template<typename T> class DependentPOD {
45*f4a2713aSLionel Sambuc   enum b { x };
foo()46*f4a2713aSLionel Sambuc   b foo() { return x; }
47*f4a2713aSLionel Sambuc };
48