reference, declarationdefinition
definition → references, declarations, derived classes, virtual overrides
reference to multiple definitions → definitions
unreferenced
    1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119
  120
  121
  122
  123
  124
  125
  126
  127
  128
  129
  130
  131
  132
  133
  134
  135
  136
  137
  138
  139
  140
  141
  142
  143
  144
  145
  146
  147
  148
  149
  150
  151
  152
  153
  154
  155
  156
  157
  158
  159
  160
  161
  162
  163
  164
  165
  166
  167
  168
  169
  170
  171
  172
  173
  174
  175
  176
  177
  178
  179
  180
  181
  182
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
// RUN: not %clang_cc1 -std=c++11 -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
namespace std {
  template <class X>
  class initializer_list {
    public:
    initializer_list();
  };
}

class Foo {
public:
  Foo();
  Foo(std::initializer_list<int>);
  bool operator==(const Foo);
  Foo operator+(const Foo);
};

#define EQ(x,y) (void)(x == y)  // expected-note 6{{defined here}}
void test_EQ() {
  Foo F;
  F = Foo{1,2};

  EQ(F,F);
  EQ(F,Foo());
  EQ(F,Foo({1,2,3}));
  EQ(Foo({1,2,3}),F);
  EQ((Foo{1,2,3}),(Foo{1,2,3}));
  EQ(F, F + F);
  EQ(F, Foo({1,2,3}) + Foo({1,2,3}));
  EQ(F, (Foo{1,2,3} + Foo{1,2,3}));

  EQ(F,Foo{1,2,3});
  // expected-error@-1 {{too many arguments provided}}
  // expected-note@-2 {{parentheses are required}}
  EQ(Foo{1,2,3},F);
  // expected-error@-1 {{too many arguments provided}}
  // expected-note@-2 {{parentheses are required}}
  EQ(Foo{1,2,3},Foo{1,2,3});
  // expected-error@-1 {{too many arguments provided}}
  // expected-note@-2 {{parentheses are required}}

  EQ(Foo{1,2,3} + Foo{1,2,3}, F);
  // expected-error@-1 {{too many arguments provided}}
  // expected-note@-2 {{parentheses are required}}
  EQ(F, Foo({1,2,3}) + Foo{1,2,3});
  // expected-error@-1 {{too many arguments provided}}
  // expected-note@-2 {{parentheses are required}}
  EQ(F, Foo{1,2,3} + Foo{1,2,3});
  // expected-error@-1 {{too many arguments provided}}
  // expected-note@-2 {{parentheses are required}}
}

// CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{33:8-33:8}:"("
// CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{33:18-33:18}:")"

// CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{36:6-36:6}:"("
// CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{36:16-36:16}:")"

// CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{39:6-39:6}:"("
// CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{39:16-39:16}:")"
// CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{39:17-39:17}:"("
// CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{39:27-39:27}:")"

// CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{43:6-43:6}:"("
// CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{43:29-43:29}:")"

// CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{46:9-46:9}:"("
// CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{46:34-46:34}:")"

// CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{49:9-49:9}:"("
// CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{49:32-49:32}:")"

#define NE(x,y) (void)(x != y)  // expected-note 6{{defined here}}
// Operator != isn't defined.  This tests that the corrected macro arguments
// are used in the macro expansion.
void test_NE() {
  Foo F;

  NE(F,F);
  // expected-error@-1 {{invalid operands}}
  NE(F,Foo());
  // expected-error@-1 {{invalid operands}}
  NE(F,Foo({1,2,3}));
  // expected-error@-1 {{invalid operands}}
  NE((Foo{1,2,3}),(Foo{1,2,3}));
  // expected-error@-1 {{invalid operands}}

  NE(F,Foo{1,2,3});
  // expected-error@-1 {{too many arguments provided}}
  // expected-note@-2 {{parentheses are required}}
  // expected-error@-3 {{invalid operands}}
  NE(Foo{1,2,3},F);
  // expected-error@-1 {{too many arguments provided}}
  // expected-note@-2 {{parentheses are required}}
  // expected-error@-3 {{invalid operands}}
  NE(Foo{1,2,3},Foo{1,2,3});
  // expected-error@-1 {{too many arguments provided}}
  // expected-note@-2 {{parentheses are required}}
  // expected-error@-3 {{invalid operands}}

  NE(Foo{1,2,3} + Foo{1,2,3}, F);
  // expected-error@-1 {{too many arguments provided}}
  // expected-note@-2 {{parentheses are required}}
  // expected-error@-3 {{invalid operands}}
  NE(F, Foo({1,2,3}) + Foo{1,2,3});
  // expected-error@-1 {{too many arguments provided}}
  // expected-note@-2 {{parentheses are required}}
  // expected-error@-3 {{invalid operands}}
  NE(F, Foo{1,2,3} + Foo{1,2,3});
  // expected-error@-1 {{too many arguments provided}}
  // expected-note@-2 {{parentheses are required}}
  // expected-error@-3 {{invalid operands}}
}

// CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{89:8-89:8}:"("
// CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{89:18-89:18}:")"

// CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{93:6-93:6}:"("
// CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{93:16-93:16}:")"

// CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{97:6-97:6}:"("
// CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{97:16-97:16}:")"
// CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{97:17-97:17}:"("
// CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{97:27-97:27}:")"

// CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{102:6-102:6}:"("
// CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{102:29-102:29}:")"

// CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{106:9-106:9}:"("
// CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{106:34-106:34}:")"

// CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{110:9-110:9}:"("
// CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{110:32-110:32}:")"

#define INIT(var, init) Foo var = init; // expected-note 3{{defined here}}
// Can't use an initializer list as a macro argument.  The commas in the list
// will be interpretted as argument separaters and adding parenthesis will
// make it no longer an initializer list.
void test() {
  INIT(a, Foo());
  INIT(b, Foo({1, 2, 3}));
  INIT(c, Foo());

  INIT(d, Foo{1, 2, 3});
  // expected-error@-1 {{too many arguments provided}}
  // expected-note@-2 {{parentheses are required}}

  // Can't be fixed by parentheses.
  INIT(e, {1, 2, 3});
  // expected-error@-1 {{too many arguments provided}}
  // expected-error@-2 {{use of undeclared identifier}}
  // expected-note@-3 {{cannot use initializer list at the beginning of a macro argument}}

  // Can't be fixed by parentheses.
  INIT(e, {1, 2, 3} + {1, 2, 3});
  // expected-error@-1 {{too many arguments provided}}
  // expected-error@-2 {{use of undeclared identifier}}
  // expected-note@-3 {{cannot use initializer list at the beginning of a macro argument}}
}

// CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{145:11-145:11}:"("
// CHECK: fix-it:"{{.*}}macro_with_initializer_list.cpp":{145:23-145:23}:")"

#define M(name,a,b,c,d,e,f,g,h,i,j,k,l) \
  Foo name = a + b + c + d + e + f + g + h + i + j + k + l;
// expected-note@-2 2{{defined here}}
void test2() {
  M(F1, Foo(), Foo(), Foo(), Foo(), Foo(), Foo(),
        Foo(), Foo(), Foo(), Foo(), Foo(), Foo());

  M(F2, Foo{1,2,3}, Foo{1,2,3}, Foo{1,2,3}, Foo{1,2,3}, Foo{1,2,3}, Foo{1,2,3},
        Foo{1,2,3}, Foo{1,2,3}, Foo{1,2,3}, Foo{1,2,3}, Foo{1,2,3}, Foo{1,2,3});
  // expected-error@-2 {{too many arguments provided}}
  // expected-note@-3 {{parentheses are required}}

  M(F3, {1,2,3}, {1,2,3}, {1,2,3}, {1,2,3}, {1,2,3}, {1,2,3},
        {1,2,3}, {1,2,3}, {1,2,3}, {1,2,3}, {1,2,3}, {1,2,3});
  // expected-error@-2 {{too many arguments provided}}
  // expected-error@-3 {{use of undeclared identifier}}
  // expected-note@-4 {{cannot use initializer list at the beginning of a macro argument}}
}