summaryrefslogtreecommitdiffstats
path: root/tests/cxx/varargs_and_references.cc
blob: 7f4b7cb0ea031872df191fe2fc0693a9f6e2b240 (plain) (blame)
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
//===--- varargs_and_references.cc - test input file for iwyu -------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

// When passing a class to a function that takes vararg arguments,
// compilers seem to require the full type information for the class
// (though the behavior is technically undefined).  Test that IWYU
// notices this.  (It only matters for references, of course.)
//
// TODO(csilvers): Clarify what the intended behavior here is; see discussion on
// OCL 23543695.

#include "tests/cxx/direct.h"

// Just to make things more complicated, put a default argument before
// the varargs.
int Function(int x, int y = 5, ...) { return 0; }

// To make things even *more* complicated, try a function pointer.
int (*function_p)(int, int, ...) = &Function;

int main() {
  // IWYU: IndirectClass is...*indirect.h
  IndirectClass ic;
  // IWYU: IndirectClass needs a declaration
  const IndirectClass& ref = ic;
  // IWYU: IndirectClass is...*indirect.h
  (void)sizeof(Function(1, 2, ref));
  // IWYU: IndirectClass is...*indirect.h
  (void)sizeof((*function_p)(1, 2, ref));
  // IWYU: IndirectClass is...*indirect.h
  (void)sizeof((*function_p)(1, 2, 3, 4, 5, ref));
}

/**** IWYU_SUMMARY

tests/cxx/varargs_and_references.cc should add these lines:
#include "tests/cxx/indirect.h"

tests/cxx/varargs_and_references.cc should remove these lines:
- #include "tests/cxx/direct.h"  // lines XX-XX

The full include-list for tests/cxx/varargs_and_references.cc:
#include "tests/cxx/indirect.h"  // for IndirectClass

***** IWYU_SUMMARY */