diff options
author | Bolshakov <bolsh.andrey@yandex.ru> | 2022-05-27 00:14:05 +0300 |
---|---|---|
committer | Kim Gräsman <kim.grasman@gmail.com> | 2022-06-13 07:47:21 +0200 |
commit | 4c0f39615982c57a9cb313c971c6f45fca1cc1fe (patch) | |
tree | 255121449b0b4e876e29f51536dc1aa6f7deed30 | |
parent | 12d2c18fa68a6712d6a4bea3a11c50687ff7646c (diff) |
Tests on enum opaque declarations
-rw-r--r-- | tests/c/enum-direct.h | 10 | ||||
-rw-r--r-- | tests/c/enum-indirect.h | 10 | ||||
-rw-r--r-- | tests/c/enum.c | 30 | ||||
-rw-r--r-- | tests/cxx/enums-d1.h | 25 | ||||
-rw-r--r-- | tests/cxx/enums-i1.h | 15 | ||||
-rw-r--r-- | tests/cxx/enums-i2.h | 15 | ||||
-rw-r--r-- | tests/cxx/enums-i3.h | 17 | ||||
-rw-r--r-- | tests/cxx/enums-i4.h | 15 | ||||
-rw-r--r-- | tests/cxx/enums.cc | 90 |
9 files changed, 227 insertions, 0 deletions
diff --git a/tests/c/enum-direct.h b/tests/c/enum-direct.h new file mode 100644 index 0000000..97b39d3 --- /dev/null +++ b/tests/c/enum-direct.h @@ -0,0 +1,10 @@ +//===--- enum-direct.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. +// +//===----------------------------------------------------------------------===// + +#include "tests/c/enum-indirect.h" diff --git a/tests/c/enum-indirect.h b/tests/c/enum-indirect.h new file mode 100644 index 0000000..6631e96 --- /dev/null +++ b/tests/c/enum-indirect.h @@ -0,0 +1,10 @@ +//===--- enum-indirect.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. +// +//===----------------------------------------------------------------------===// + +enum Enum { A, B, C }; diff --git a/tests/c/enum.c b/tests/c/enum.c new file mode 100644 index 0000000..810e844 --- /dev/null +++ b/tests/c/enum.c @@ -0,0 +1,30 @@ +//===--- enum.c - 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. +// +//===----------------------------------------------------------------------===// + +// IWYU_ARGS: -I . + +// Test that IWYU doesn't suggest to forward-declare C-style enumeration. + +#include "tests/c/enum-direct.h" + +// IWYU: Enum is...*enum-indirect.h +enum Enum e; + +/**** IWYU_SUMMARY + +tests/c/enum.c should add these lines: +#include "tests/c/enum-indirect.h" + +tests/c/enum.c should remove these lines: +- #include "tests/c/enum-direct.h" // lines XX-XX + +The full include-list for tests/c/enum.c: +#include "tests/c/enum-indirect.h" // for Enum + +***** IWYU_SUMMARY */ diff --git a/tests/cxx/enums-d1.h b/tests/cxx/enums-d1.h new file mode 100644 index 0000000..622cc53 --- /dev/null +++ b/tests/cxx/enums-d1.h @@ -0,0 +1,25 @@ +//===--- enums-d1.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. +// +//===----------------------------------------------------------------------===// + +#include "tests/cxx/enums-i1.h" +#include "tests/cxx/enums-i2.h" +#include "tests/cxx/enums-i3.h" +#include "tests/cxx/enums-i4.h" + +enum class DirectEnum1 { A, B, C }; + +enum class DirectEnum2 : int { A, B, C }; + +enum struct DirectEnum3 : unsigned long long { A, B, C }; + +namespace ns { +enum DirectEnum4 : int { A, B, C }; +} + +enum class DirectEnum5 : long { A, B, C }; diff --git a/tests/cxx/enums-i1.h b/tests/cxx/enums-i1.h new file mode 100644 index 0000000..e3adf98 --- /dev/null +++ b/tests/cxx/enums-i1.h @@ -0,0 +1,15 @@ +//===--- enums-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_ENUMS_I1_H_ +#define INCLUDE_WHAT_YOU_USE_TESTS_CXX_ENUMS_I1_H_ + +enum IndirectEnum1 { A, B, C }; + +#endif // INCLUDE_WHAT_YOU_USE_TESTS_CXX_ENUMS_I1_H_ diff --git a/tests/cxx/enums-i2.h b/tests/cxx/enums-i2.h new file mode 100644 index 0000000..b44c554 --- /dev/null +++ b/tests/cxx/enums-i2.h @@ -0,0 +1,15 @@ +//===--- enums-i2.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_ENUMS_I2_H_ +#define INCLUDE_WHAT_YOU_USE_TESTS_CXX_ENUMS_I2_H_ + +enum class IndirectEnum2 : int { A, B, C }; + +#endif // INCLUDE_WHAT_YOU_USE_TESTS_CXX_ENUMS_I2_H_ diff --git a/tests/cxx/enums-i3.h b/tests/cxx/enums-i3.h new file mode 100644 index 0000000..9682d98 --- /dev/null +++ b/tests/cxx/enums-i3.h @@ -0,0 +1,17 @@ +//===--- enums-i3.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_ENUMS_I3_H_ +#define INCLUDE_WHAT_YOU_USE_TESTS_CXX_ENUMS_I3_H_ + +struct Struct1 { + enum class IndirectEnum3 { A, B, C }; +}; + +#endif // INCLUDE_WHAT_YOU_USE_TESTS_CXX_ENUMS_I3_H_ diff --git a/tests/cxx/enums-i4.h b/tests/cxx/enums-i4.h new file mode 100644 index 0000000..ea254ae --- /dev/null +++ b/tests/cxx/enums-i4.h @@ -0,0 +1,15 @@ +//===--- enums-i4.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_ENUMS_I4_H_ +#define INCLUDE_WHAT_YOU_USE_TESTS_CXX_ENUMS_I4_H_ + +enum { UnnamedEnumItem1, UnnamedEnumItem2, UnnamedEnumItem3 }; + +#endif // INCLUDE_WHAT_YOU_USE_TESTS_CXX_ENUMS_I4_H_ diff --git a/tests/cxx/enums.cc b/tests/cxx/enums.cc new file mode 100644 index 0000000..f1d7679 --- /dev/null +++ b/tests/cxx/enums.cc @@ -0,0 +1,90 @@ +//===--- enums.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. +// +//===----------------------------------------------------------------------===// + +// IWYU_ARGS: -I . + +// Test enumeration forward (opaque) declarations. + +#include "tests/cxx/enums-d1.h" + +// Test that IWYU considers this as a forward declaration +// which should be kept. +enum class DirectEnum5 : long; +// Test that opaque redeclaration should not lead to ignoring +// of IndirectEnum2::A use. +enum class IndirectEnum2 : int; + +// For scoped and unscoped enums with fixed underlying type, opaque declaration +// is sufficient. +DirectEnum1 de1; +DirectEnum2 de2; +DirectEnum3 de3; +ns::DirectEnum4 de4; +DirectEnum5 de5; + +// For an unscoped enum without explicitly specified underlying type, full +// definition is needed. +// IWYU: IndirectEnum1 is...*enums-i1.h +IndirectEnum1 ie1; +// When an enum item is mentioned, full definition of the enum is needed. +// IWYU: IndirectEnum2 is...*enums-i2.h +IndirectEnum2 ie2 = IndirectEnum2::A; +// In order to mention a nested enum, full type of the owning class is needed. +// IWYU: Struct1 is...*enums-i3.h +Struct1::IndirectEnum3 ie3; +// For unnamed enumeration, enumerators are reported. +// IWYU: UnnamedEnumItem2 is...*enums-i4.h +auto ie4 = UnnamedEnumItem2; + +template <typename T1, typename T2> +struct Template { + T1 t1; + T2 t2 = T2::B; +}; + +// Only IndirectEnum2 item is used inside Template specialization. +// IWYU: IndirectEnum2 is...*enums-i2.h +Template<DirectEnum1, IndirectEnum2> t; + +struct Struct2 { + // Test that IWYU doesn't suggest to remove this declaration. + enum class Nested; +}; + +enum class Struct2::Nested { A, B, C }; + +/**** IWYU_SUMMARY + +tests/cxx/enums.cc should add these lines: +#include "tests/cxx/enums-i1.h" +#include "tests/cxx/enums-i2.h" +#include "tests/cxx/enums-i3.h" +#include "tests/cxx/enums-i4.h" +enum class DirectEnum1; +enum class DirectEnum2 : int; +enum struct DirectEnum3 : unsigned long long; +namespace ns { enum DirectEnum4 : int; } + +tests/cxx/enums.cc should remove these lines: +- #include "tests/cxx/enums-d1.h" // lines XX-XX +- enum class IndirectEnum2 : int; // lines XX-XX + +The full include-list for tests/cxx/enums.cc: +#include "tests/cxx/enums-i1.h" // for IndirectEnum1 +#include "tests/cxx/enums-i2.h" // for IndirectEnum2 +#include "tests/cxx/enums-i3.h" // for Struct1 +#include "tests/cxx/enums-i4.h" // for UnnamedEnumItem2 +enum class DirectEnum1; +enum class DirectEnum2 : int; +enum class DirectEnum5 : long; // lines XX-XX +enum class Struct2::Nested; // lines XX-XX +enum struct DirectEnum3 : unsigned long long; +namespace ns { enum DirectEnum4 : int; } + +***** IWYU_SUMMARY */ |