//===--- badinc-i1.h - 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. // //===----------------------------------------------------------------------===// #ifndef INCLUDE_WHAT_YOU_USE_TESTS_CXX_BADINC_I1_H_ #define INCLUDE_WHAT_YOU_USE_TESTS_CXX_BADINC_I1_H_ #include // For offsetof (in badinc.cc). #include // also included from badinc-d1.h -- before this file #include // also included from badinc-d3.h -- after this file #include "tests/cxx/badinc-d2.h" #include "tests/cxx/badinc-i2.h" #if 0 #include "tests/cxx/badinc-i5.h" #endif #include "tests/cxx/badinc-i6.h" #define MACRO_CALLING_I6_FUNCTION I6_Function() #define I1_MACRO_SYMBOL_WITHOUT_VALUE #define I1_MACRO_SYMBOL_WITH_VALUE 1 #define I1_MACRO_SYMBOL_WITH_VALUE0 0 #define I1_MACRO_SYMBOL_WITH_VALUE2 2 // Lets us test handling of operator<< when first argument is a macro. #define I1_MACRO_LOGGING_CLASS \ I2_OperatorDefinedInI1Class logging_class = I2_OperatorDefinedInI1Class() // The types. enum I1_Enum { I11, I12, I13 }; const int kI1ConstInt = 5; typedef I2_Typedef I1_Typedef; // nested typedefs struct I1_Struct { int a; float b; I1_Enum c; }; union I1_Union { I1_Struct* a; I1_Enum b; int c; }; typedef struct { int a; float b; } I1_UnnamedStruct; class I1_Base { public: virtual ~I1_Base() {} }; class I1_Class : public I1_Base { public: explicit I1_Class(int a) { a_ = a; } I1_Class() { a_ = 1; } // Call with T == I1_NamespaceClass, say. template I1_Class(const T* obj, int dummy) : a_(obj->a) { } struct NestedStruct; // defined below template struct NestedTemplateStruct { }; int a() const { return a_; } I1_Typedef b() const { return static_cast(a_); } template I1_Enum I1_ClassTemplateFunction(A a) { return I11; } template static I1_Enum I1_StaticClassTemplateFunction(A a) { return I12; } static int s() { return 1; } typedef int I1_Class_int; private: int a_; static I1_Class_int s_; }; I1_Class::I1_Class_int I1_Class::s_; struct I1_Class::NestedStruct { typedef int NestedStructTypedef; }; class I1_SiblingClass : public I1_Base { }; class I1_Subclass : public D2_Class { }; template class I1_TemplateClass { public: I1_TemplateClass() { BAR bar; (void)bar; } I1_TemplateClass(FOO a) { a_ = a; } I1_TemplateClass(I1_Union a) { } template I1_TemplateClass(CTOR ctor_arg, bool unused) { } ~I1_TemplateClass() { FOO* tmp; tmp = &a_; BAR bar; (void)bar; } FOO a() { return a_; } void new_delete_bar() { BAR* bar = new BAR(); delete bar; } typedef int I1_TemplateClass_int; private: FOO a_; I1_TemplateClass* next_; // test type-recursion }; template class I1_TemplateSubclass : public I1_TemplateClass { }; template class I1_TemplateMethodOnlyClass { public: FOO a() { FOO retval; return retval; } FOO* b() { FOO* retval = NULL; return retval; } template BAR c() { return BAR(); } template BAR* d() { BAR* retval = NULL; return retval; } template int e(BAR* b) { return (int)b->size(); } template static int s(BAR b) { // BAR should be a ptr type FOO foo; return foo.a() + (int)b->size(); } template static int t() { // BAR should be I1_Class I1_TemplateClass tc; return tc.a(); } // BAR should be I1_TemplateClass template class BAR> static int tt() { BAR t; return t.a().a(); } }; template class I1_TemplateClassFwdDeclaredInD2 { }; template class I1_TypedefOnly_Class { public: typedef typename FOO::I1_Class_int i; // best if FOO == I1_Class }; // This class is only referenced via D1_I1_Typedef, in badinc-d1.h class I1_Typedef_Class { public: I1_Typedef_Class() { a_ = 1; } int a() { return a_; } private: int a_; }; template class I1_const_ptr { public: explicit I1_const_ptr(const T* ptr) : ptr_(ptr) { } ~I1_const_ptr() { delete ptr_; } const T& operator*() { return *ptr_; } const T* operator->() { return ptr_; } int operator~() { return deref_a(); } void del() { delete (((ptr_))); } void indirect_del() { del(); } int deref_a() { return (*ptr_)->a(); } private: const T* ptr_; }; // Try an out-of-line operator too, both regular-style and yoda-style. template bool operator==(I1_const_ptr& ptr, const T& val) { return &*ptr == &val; } template bool operator==(const T& val, I1_const_ptr& ptr) { return &*ptr == &val; } class I1_DefinedInCc_Class; // This class is never used, but has an empty destructor defined in // badinc.cc. We want to make sure we don't get '(ptr only)' for it. class EmptyDestructorClass { public: EmptyDestructorClass() { } ~EmptyDestructorClass(); }; // This is needed by Cc_TemplateClass. OperateOn is from badinc.h template class OperateOn; // forward declare, from badinc.h template<> class OperateOn { }; template class OperateOn > { }; typedef I2_Class I1_I2_Class_Typedef; typedef I1_Class* I1_ClassPtr; typedef I1_Enum (*I1_FunctionPtr)(I1_Class*); I1_Enum I1_Function(I1_Class* c) { return I11; } inline void I1_OverloadedFunction(int i) { } inline void I1_OverloadedFunction(float f) { } template void I1_OverloadedFunction(const T& t) { } inline void I1_And_I2_OverloadedFunction(int i) { } template I1_Enum I1_TemplateFunction(A a) { return I11; } I2_OperatorDefinedInI1Class& I2_OperatorDefinedInI1Class::operator<<(int i) { return *this; } class I1_ForwardDeclareClass; struct I1_ManyPtrStruct { int a; }; struct I1_PtrDereferenceStruct { int a; }; class I1_PtrDereferenceClass { public: int a() { return 1; } }; class I1_PtrDereferenceStatic { public: static int a() { return 1; } }; class I1_StaticMethod { public: static int a() { return 1; } }; class I1_MemberPtr { public: int a() { return 1; } }; class I1_PtrAndUseOnSameLine { public: int a() { return 1; } }; class I1_SubclassesI2Class : public I2_Class { public: int a() { return 1; } }; namespace i1_ns { class I1_NamespaceClass { public: int a; }; struct I1_NamespaceStruct { int a; }; struct I1_UnusedNamespaceStruct { int a; }; template void I1_NamespaceTemplateFn(T t) { } } // Defines a class that's declared in badinc.h. class H_Class::H_Class_DefinedInI1 { }; // The vars. Just a few. int i1_int = 6; I1_Enum i1_i1_enum; I1_Union i1_i1_union; I1_UnnamedStruct i1_i1_unnamed_struct; I1_Class* i1_i1_classptr; D2_Class i1_d2_class; namespace i1_ns { int i1_int_global; } namespace i1_ns { namespace i1_subns { int i1_int_globalsub; } } namespace i1_ns2 { int i1_int_global2; } namespace i1_ns2 { namespace i1_subns { int i1_int_global2sub; } } namespace i1_ns3 { int i1_int_global3; } namespace i1_ns3 { namespace i1_subns { int i1_int_global3sub; } } namespace i1_ns4 { int i1_int_global4; } namespace i1_ns4 { namespace i1_subns { int i1_int_global4sub; } } namespace i1_ns5 { int i1_unused_global; } int i1_GlobalFunction(void) { return 1; } #endif // INCLUDE_WHAT_YOU_USE_TESTS_CXX_BADINC_I1_H_