1 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -ast-dump=json %s | FileCheck %s
2 
3 struct S {
SS4   S() {}
~SS5   ~S() {}
6 };
7 
8 void func(const int &);
9 
BindTemp()10 void BindTemp() {
11   const S &s = S();
12 }
13 
MaterializeTemp()14 void MaterializeTemp() {
15   const int &i = 1.0;
16 
17   float f = 1.0f;
18   func(f);
19 }
20 
21 // NOTE: CHECK lines have been autogenerated by gen_ast_dump_json_test.py
22 // using --filters=ExprWithCleanups
23 
24 
25 // CHECK:  "kind": "ExprWithCleanups",
26 // CHECK-NEXT:  "range": {
27 // CHECK-NEXT:   "begin": {
28 // CHECK-NEXT:    "offset": 184,
29 // CHECK-NEXT:    "col": 16,
30 // CHECK-NEXT:    "tokLen": 1
31 // CHECK-NEXT:   },
32 // CHECK-NEXT:   "end": {
33 // CHECK-NEXT:    "offset": 186,
34 // CHECK-NEXT:    "col": 18,
35 // CHECK-NEXT:    "tokLen": 1
36 // CHECK-NEXT:   }
37 // CHECK-NEXT:  },
38 // CHECK-NEXT:  "type": {
39 // CHECK-NEXT:   "qualType": "const S"
40 // CHECK-NEXT:  },
41 // CHECK-NEXT:  "valueCategory": "lvalue",
42 // CHECK-NEXT:  "cleanupsHaveSideEffects": true,
43 // CHECK-NEXT:  "inner": [
44 // CHECK-NEXT:   {
45 // CHECK-NEXT:    "id": "0x{{.*}}",
46 // CHECK-NEXT:    "kind": "MaterializeTemporaryExpr",
47 // CHECK-NEXT:    "range": {
48 // CHECK-NEXT:     "begin": {
49 // CHECK-NEXT:      "offset": 184,
50 // CHECK-NEXT:      "col": 16,
51 // CHECK-NEXT:      "tokLen": 1
52 // CHECK-NEXT:     },
53 // CHECK-NEXT:     "end": {
54 // CHECK-NEXT:      "offset": 186,
55 // CHECK-NEXT:      "col": 18,
56 // CHECK-NEXT:      "tokLen": 1
57 // CHECK-NEXT:     }
58 // CHECK-NEXT:    },
59 // CHECK-NEXT:    "type": {
60 // CHECK-NEXT:     "qualType": "const S"
61 // CHECK-NEXT:    },
62 // CHECK-NEXT:    "valueCategory": "lvalue",
63 // CHECK-NEXT:    "extendingDecl": {
64 // CHECK-NEXT:     "id": "0x{{.*}}",
65 // CHECK-NEXT:     "kind": "VarDecl",
66 // CHECK-NEXT:     "name": "s",
67 // CHECK-NEXT:     "type": {
68 // CHECK-NEXT:      "qualType": "const S &"
69 // CHECK-NEXT:     }
70 // CHECK-NEXT:    },
71 // CHECK-NEXT:    "storageDuration": "automatic",
72 // CHECK-NEXT:    "boundToLValueRef": true,
73 // CHECK-NEXT:    "inner": [
74 // CHECK-NEXT:     {
75 // CHECK-NEXT:      "id": "0x{{.*}}",
76 // CHECK-NEXT:      "kind": "ImplicitCastExpr",
77 // CHECK-NEXT:      "range": {
78 // CHECK-NEXT:       "begin": {
79 // CHECK-NEXT:        "offset": 184,
80 // CHECK-NEXT:        "col": 16,
81 // CHECK-NEXT:        "tokLen": 1
82 // CHECK-NEXT:       },
83 // CHECK-NEXT:       "end": {
84 // CHECK-NEXT:        "offset": 186,
85 // CHECK-NEXT:        "col": 18,
86 // CHECK-NEXT:        "tokLen": 1
87 // CHECK-NEXT:       }
88 // CHECK-NEXT:      },
89 // CHECK-NEXT:      "type": {
90 // CHECK-NEXT:       "qualType": "const S"
91 // CHECK-NEXT:      },
92 // CHECK-NEXT:      "valueCategory": "rvalue",
93 // CHECK-NEXT:      "castKind": "NoOp",
94 // CHECK-NEXT:      "inner": [
95 // CHECK-NEXT:       {
96 // CHECK-NEXT:        "id": "0x{{.*}}",
97 // CHECK-NEXT:        "kind": "CXXBindTemporaryExpr",
98 // CHECK-NEXT:        "range": {
99 // CHECK-NEXT:         "begin": {
100 // CHECK-NEXT:          "offset": 184,
101 // CHECK-NEXT:          "col": 16,
102 // CHECK-NEXT:          "tokLen": 1
103 // CHECK-NEXT:         },
104 // CHECK-NEXT:         "end": {
105 // CHECK-NEXT:          "offset": 186,
106 // CHECK-NEXT:          "col": 18,
107 // CHECK-NEXT:          "tokLen": 1
108 // CHECK-NEXT:         }
109 // CHECK-NEXT:        },
110 // CHECK-NEXT:        "type": {
111 // CHECK-NEXT:         "qualType": "S"
112 // CHECK-NEXT:        },
113 // CHECK-NEXT:        "valueCategory": "rvalue",
114 // CHECK-NEXT:        "temp": "0x{{.*}}",
115 // CHECK-NEXT:        "dtor": {
116 // CHECK-NEXT:         "id": "0x{{.*}}",
117 // CHECK-NEXT:         "kind": "CXXDestructorDecl",
118 // CHECK-NEXT:         "name": "~S",
119 // CHECK-NEXT:         "type": {
120 // CHECK-NEXT:          "qualType": "void () noexcept"
121 // CHECK-NEXT:         }
122 // CHECK-NEXT:        },
123 // CHECK-NEXT:        "inner": [
124 // CHECK-NEXT:         {
125 // CHECK-NEXT:          "id": "0x{{.*}}",
126 // CHECK-NEXT:          "kind": "CXXTemporaryObjectExpr",
127 // CHECK-NEXT:          "range": {
128 // CHECK-NEXT:           "begin": {
129 // CHECK-NEXT:            "offset": 184,
130 // CHECK-NEXT:            "col": 16,
131 // CHECK-NEXT:            "tokLen": 1
132 // CHECK-NEXT:           },
133 // CHECK-NEXT:           "end": {
134 // CHECK-NEXT:            "offset": 186,
135 // CHECK-NEXT:            "col": 18,
136 // CHECK-NEXT:            "tokLen": 1
137 // CHECK-NEXT:           }
138 // CHECK-NEXT:          },
139 // CHECK-NEXT:          "type": {
140 // CHECK-NEXT:           "qualType": "S"
141 // CHECK-NEXT:          },
142 // CHECK-NEXT:          "valueCategory": "rvalue",
143 // CHECK-NEXT:          "ctorType": {
144 // CHECK-NEXT:           "qualType": "void ()"
145 // CHECK-NEXT:          },
146 // CHECK-NEXT:          "hadMultipleCandidates": true,
147 // CHECK-NEXT:          "constructionKind": "complete"
148 // CHECK-NEXT:         }
149 // CHECK-NEXT:        ]
150 // CHECK-NEXT:       }
151 // CHECK-NEXT:      ]
152 // CHECK-NEXT:     }
153 // CHECK-NEXT:    ]
154 // CHECK-NEXT:   }
155 // CHECK-NEXT:  ]
156 // CHECK-NEXT: }
157 
158 
159 // CHECK:  "kind": "ExprWithCleanups",
160 // CHECK-NEXT:  "range": {
161 // CHECK-NEXT:   "begin": {
162 // CHECK-NEXT:    "offset": 234,
163 // CHECK-NEXT:    "col": 18,
164 // CHECK-NEXT:    "tokLen": 3
165 // CHECK-NEXT:   },
166 // CHECK-NEXT:   "end": {
167 // CHECK-NEXT:    "offset": 234,
168 // CHECK-NEXT:    "col": 18,
169 // CHECK-NEXT:    "tokLen": 3
170 // CHECK-NEXT:   }
171 // CHECK-NEXT:  },
172 // CHECK-NEXT:  "type": {
173 // CHECK-NEXT:   "qualType": "const int"
174 // CHECK-NEXT:  },
175 // CHECK-NEXT:  "valueCategory": "lvalue",
176 // CHECK-NEXT:  "inner": [
177 // CHECK-NEXT:   {
178 // CHECK-NEXT:    "id": "0x{{.*}}",
179 // CHECK-NEXT:    "kind": "MaterializeTemporaryExpr",
180 // CHECK-NEXT:    "range": {
181 // CHECK-NEXT:     "begin": {
182 // CHECK-NEXT:      "offset": 234,
183 // CHECK-NEXT:      "col": 18,
184 // CHECK-NEXT:      "tokLen": 3
185 // CHECK-NEXT:     },
186 // CHECK-NEXT:     "end": {
187 // CHECK-NEXT:      "offset": 234,
188 // CHECK-NEXT:      "col": 18,
189 // CHECK-NEXT:      "tokLen": 3
190 // CHECK-NEXT:     }
191 // CHECK-NEXT:    },
192 // CHECK-NEXT:    "type": {
193 // CHECK-NEXT:     "qualType": "const int"
194 // CHECK-NEXT:    },
195 // CHECK-NEXT:    "valueCategory": "lvalue",
196 // CHECK-NEXT:    "extendingDecl": {
197 // CHECK-NEXT:     "id": "0x{{.*}}",
198 // CHECK-NEXT:     "kind": "VarDecl",
199 // CHECK-NEXT:     "name": "i",
200 // CHECK-NEXT:     "type": {
201 // CHECK-NEXT:      "qualType": "const int &"
202 // CHECK-NEXT:     }
203 // CHECK-NEXT:    },
204 // CHECK-NEXT:    "storageDuration": "automatic",
205 // CHECK-NEXT:    "boundToLValueRef": true,
206 // CHECK-NEXT:    "inner": [
207 // CHECK-NEXT:     {
208 // CHECK-NEXT:      "id": "0x{{.*}}",
209 // CHECK-NEXT:      "kind": "ImplicitCastExpr",
210 // CHECK-NEXT:      "range": {
211 // CHECK-NEXT:       "begin": {
212 // CHECK-NEXT:        "offset": 234,
213 // CHECK-NEXT:        "col": 18,
214 // CHECK-NEXT:        "tokLen": 3
215 // CHECK-NEXT:       },
216 // CHECK-NEXT:       "end": {
217 // CHECK-NEXT:        "offset": 234,
218 // CHECK-NEXT:        "col": 18,
219 // CHECK-NEXT:        "tokLen": 3
220 // CHECK-NEXT:       }
221 // CHECK-NEXT:      },
222 // CHECK-NEXT:      "type": {
223 // CHECK-NEXT:       "qualType": "const int"
224 // CHECK-NEXT:      },
225 // CHECK-NEXT:      "valueCategory": "rvalue",
226 // CHECK-NEXT:      "castKind": "FloatingToIntegral",
227 // CHECK-NEXT:      "inner": [
228 // CHECK-NEXT:       {
229 // CHECK-NEXT:        "id": "0x{{.*}}",
230 // CHECK-NEXT:        "kind": "FloatingLiteral",
231 // CHECK-NEXT:        "range": {
232 // CHECK-NEXT:         "begin": {
233 // CHECK-NEXT:          "offset": 234,
234 // CHECK-NEXT:          "col": 18,
235 // CHECK-NEXT:          "tokLen": 3
236 // CHECK-NEXT:         },
237 // CHECK-NEXT:         "end": {
238 // CHECK-NEXT:          "offset": 234,
239 // CHECK-NEXT:          "col": 18,
240 // CHECK-NEXT:          "tokLen": 3
241 // CHECK-NEXT:         }
242 // CHECK-NEXT:        },
243 // CHECK-NEXT:        "type": {
244 // CHECK-NEXT:         "qualType": "double"
245 // CHECK-NEXT:        },
246 // CHECK-NEXT:        "valueCategory": "rvalue",
247 // CHECK-NEXT:        "value": "1"
248 // CHECK-NEXT:       }
249 // CHECK-NEXT:      ]
250 // CHECK-NEXT:     }
251 // CHECK-NEXT:    ]
252 // CHECK-NEXT:   }
253 // CHECK-NEXT:  ]
254 // CHECK-NEXT: }
255 
256 
257 // CHECK:  "kind": "ExprWithCleanups",
258 // CHECK-NEXT:  "range": {
259 // CHECK-NEXT:   "begin": {
260 // CHECK-NEXT:    "offset": 260,
261 // CHECK-NEXT:    "line": 18,
262 // CHECK-NEXT:    "col": 3,
263 // CHECK-NEXT:    "tokLen": 4
264 // CHECK-NEXT:   },
265 // CHECK-NEXT:   "end": {
266 // CHECK-NEXT:    "offset": 266,
267 // CHECK-NEXT:    "col": 9,
268 // CHECK-NEXT:    "tokLen": 1
269 // CHECK-NEXT:   }
270 // CHECK-NEXT:  },
271 // CHECK-NEXT:  "type": {
272 // CHECK-NEXT:   "qualType": "void"
273 // CHECK-NEXT:  },
274 // CHECK-NEXT:  "valueCategory": "rvalue",
275 // CHECK-NEXT:  "inner": [
276 // CHECK-NEXT:   {
277 // CHECK-NEXT:    "id": "0x{{.*}}",
278 // CHECK-NEXT:    "kind": "CallExpr",
279 // CHECK-NEXT:    "range": {
280 // CHECK-NEXT:     "begin": {
281 // CHECK-NEXT:      "offset": 260,
282 // CHECK-NEXT:      "col": 3,
283 // CHECK-NEXT:      "tokLen": 4
284 // CHECK-NEXT:     },
285 // CHECK-NEXT:     "end": {
286 // CHECK-NEXT:      "offset": 266,
287 // CHECK-NEXT:      "col": 9,
288 // CHECK-NEXT:      "tokLen": 1
289 // CHECK-NEXT:     }
290 // CHECK-NEXT:    },
291 // CHECK-NEXT:    "type": {
292 // CHECK-NEXT:     "qualType": "void"
293 // CHECK-NEXT:    },
294 // CHECK-NEXT:    "valueCategory": "rvalue",
295 // CHECK-NEXT:    "inner": [
296 // CHECK-NEXT:     {
297 // CHECK-NEXT:      "id": "0x{{.*}}",
298 // CHECK-NEXT:      "kind": "ImplicitCastExpr",
299 // CHECK-NEXT:      "range": {
300 // CHECK-NEXT:       "begin": {
301 // CHECK-NEXT:        "offset": 260,
302 // CHECK-NEXT:        "col": 3,
303 // CHECK-NEXT:        "tokLen": 4
304 // CHECK-NEXT:       },
305 // CHECK-NEXT:       "end": {
306 // CHECK-NEXT:        "offset": 260,
307 // CHECK-NEXT:        "col": 3,
308 // CHECK-NEXT:        "tokLen": 4
309 // CHECK-NEXT:       }
310 // CHECK-NEXT:      },
311 // CHECK-NEXT:      "type": {
312 // CHECK-NEXT:       "qualType": "void (*)(const int &)"
313 // CHECK-NEXT:      },
314 // CHECK-NEXT:      "valueCategory": "rvalue",
315 // CHECK-NEXT:      "castKind": "FunctionToPointerDecay",
316 // CHECK-NEXT:      "inner": [
317 // CHECK-NEXT:       {
318 // CHECK-NEXT:        "id": "0x{{.*}}",
319 // CHECK-NEXT:        "kind": "DeclRefExpr",
320 // CHECK-NEXT:        "range": {
321 // CHECK-NEXT:         "begin": {
322 // CHECK-NEXT:          "offset": 260,
323 // CHECK-NEXT:          "col": 3,
324 // CHECK-NEXT:          "tokLen": 4
325 // CHECK-NEXT:         },
326 // CHECK-NEXT:         "end": {
327 // CHECK-NEXT:          "offset": 260,
328 // CHECK-NEXT:          "col": 3,
329 // CHECK-NEXT:          "tokLen": 4
330 // CHECK-NEXT:         }
331 // CHECK-NEXT:        },
332 // CHECK-NEXT:        "type": {
333 // CHECK-NEXT:         "qualType": "void (const int &)"
334 // CHECK-NEXT:        },
335 // CHECK-NEXT:        "valueCategory": "lvalue",
336 // CHECK-NEXT:        "referencedDecl": {
337 // CHECK-NEXT:         "id": "0x{{.*}}",
338 // CHECK-NEXT:         "kind": "FunctionDecl",
339 // CHECK-NEXT:         "name": "func",
340 // CHECK-NEXT:         "type": {
341 // CHECK-NEXT:          "qualType": "void (const int &)"
342 // CHECK-NEXT:         }
343 // CHECK-NEXT:        }
344 // CHECK-NEXT:       }
345 // CHECK-NEXT:      ]
346 // CHECK-NEXT:     },
347 // CHECK-NEXT:     {
348 // CHECK-NEXT:      "id": "0x{{.*}}",
349 // CHECK-NEXT:      "kind": "MaterializeTemporaryExpr",
350 // CHECK-NEXT:      "range": {
351 // CHECK-NEXT:       "begin": {
352 // CHECK-NEXT:        "offset": 265,
353 // CHECK-NEXT:        "col": 8,
354 // CHECK-NEXT:        "tokLen": 1
355 // CHECK-NEXT:       },
356 // CHECK-NEXT:       "end": {
357 // CHECK-NEXT:        "offset": 265,
358 // CHECK-NEXT:        "col": 8,
359 // CHECK-NEXT:        "tokLen": 1
360 // CHECK-NEXT:       }
361 // CHECK-NEXT:      },
362 // CHECK-NEXT:      "type": {
363 // CHECK-NEXT:       "qualType": "const int"
364 // CHECK-NEXT:      },
365 // CHECK-NEXT:      "valueCategory": "lvalue",
366 // CHECK-NEXT:      "storageDuration": "full expression",
367 // CHECK-NEXT:      "boundToLValueRef": true,
368 // CHECK-NEXT:      "inner": [
369 // CHECK-NEXT:       {
370 // CHECK-NEXT:        "id": "0x{{.*}}",
371 // CHECK-NEXT:        "kind": "ImplicitCastExpr",
372 // CHECK-NEXT:        "range": {
373 // CHECK-NEXT:         "begin": {
374 // CHECK-NEXT:          "offset": 265,
375 // CHECK-NEXT:          "col": 8,
376 // CHECK-NEXT:          "tokLen": 1
377 // CHECK-NEXT:         },
378 // CHECK-NEXT:         "end": {
379 // CHECK-NEXT:          "offset": 265,
380 // CHECK-NEXT:          "col": 8,
381 // CHECK-NEXT:          "tokLen": 1
382 // CHECK-NEXT:         }
383 // CHECK-NEXT:        },
384 // CHECK-NEXT:        "type": {
385 // CHECK-NEXT:         "qualType": "const int"
386 // CHECK-NEXT:        },
387 // CHECK-NEXT:        "valueCategory": "rvalue",
388 // CHECK-NEXT:        "castKind": "FloatingToIntegral",
389 // CHECK-NEXT:        "inner": [
390 // CHECK-NEXT:         {
391 // CHECK-NEXT:          "id": "0x{{.*}}",
392 // CHECK-NEXT:          "kind": "ImplicitCastExpr",
393 // CHECK-NEXT:          "range": {
394 // CHECK-NEXT:           "begin": {
395 // CHECK-NEXT:            "offset": 265,
396 // CHECK-NEXT:            "col": 8,
397 // CHECK-NEXT:            "tokLen": 1
398 // CHECK-NEXT:           },
399 // CHECK-NEXT:           "end": {
400 // CHECK-NEXT:            "offset": 265,
401 // CHECK-NEXT:            "col": 8,
402 // CHECK-NEXT:            "tokLen": 1
403 // CHECK-NEXT:           }
404 // CHECK-NEXT:          },
405 // CHECK-NEXT:          "type": {
406 // CHECK-NEXT:           "qualType": "float"
407 // CHECK-NEXT:          },
408 // CHECK-NEXT:          "valueCategory": "rvalue",
409 // CHECK-NEXT:          "castKind": "LValueToRValue",
410 // CHECK-NEXT:          "inner": [
411 // CHECK-NEXT:           {
412 // CHECK-NEXT:            "id": "0x{{.*}}",
413 // CHECK-NEXT:            "kind": "DeclRefExpr",
414 // CHECK-NEXT:            "range": {
415 // CHECK-NEXT:             "begin": {
416 // CHECK-NEXT:              "offset": 265,
417 // CHECK-NEXT:              "col": 8,
418 // CHECK-NEXT:              "tokLen": 1
419 // CHECK-NEXT:             },
420 // CHECK-NEXT:             "end": {
421 // CHECK-NEXT:              "offset": 265,
422 // CHECK-NEXT:              "col": 8,
423 // CHECK-NEXT:              "tokLen": 1
424 // CHECK-NEXT:             }
425 // CHECK-NEXT:            },
426 // CHECK-NEXT:            "type": {
427 // CHECK-NEXT:             "qualType": "float"
428 // CHECK-NEXT:            },
429 // CHECK-NEXT:            "valueCategory": "lvalue",
430 // CHECK-NEXT:            "referencedDecl": {
431 // CHECK-NEXT:             "id": "0x{{.*}}",
432 // CHECK-NEXT:             "kind": "VarDecl",
433 // CHECK-NEXT:             "name": "f",
434 // CHECK-NEXT:             "type": {
435 // CHECK-NEXT:              "qualType": "float"
436 // CHECK-NEXT:             }
437 // CHECK-NEXT:            }
438 // CHECK-NEXT:           }
439 // CHECK-NEXT:          ]
440 // CHECK-NEXT:         }
441 // CHECK-NEXT:        ]
442 // CHECK-NEXT:       }
443 // CHECK-NEXT:      ]
444 // CHECK-NEXT:     }
445 // CHECK-NEXT:    ]
446 // CHECK-NEXT:   }
447 // CHECK-NEXT:  ]
448 // CHECK-NEXT: }
449