diff options
author | Kim Grasman <kim.grasman@gmail.com> | 2017-12-26 22:25:04 +0100 |
---|---|---|
committer | Kim Gräsman <kim.grasman@gmail.com> | 2018-01-01 21:40:06 +0100 |
commit | c0c9a7d220e793330f37dc0e20bb1784441e137b (patch) | |
tree | 837264059425a73b53e5ebb46325181d38fd9aa0 | |
parent | 4ea57620264b8a7a59cbf5cb0420c933f745eee4 (diff) |
Show unscoped enumerator names in why-comments
Now that Clang diagnostics for enums print unscoped enumerator names
without qualification, do the same for why-comments.
Adjust test cases to match.
-rw-r--r-- | iwyu_output.cc | 7 | ||||
-rw-r--r-- | tests/cxx/badinc.cc | 4 | ||||
-rw-r--r-- | tests/cxx/badinc.h | 4 |
3 files changed, 11 insertions, 4 deletions
diff --git a/iwyu_output.cc b/iwyu_output.cc index c176fa4..0c66010 100644 --- a/iwyu_output.cc +++ b/iwyu_output.cc @@ -43,6 +43,7 @@ using clang::CXXMethodDecl; using clang::CXXRecordDecl; using clang::Decl; using clang::DeclContext; +using clang::EnumDecl; using clang::FileEntry; using clang::FunctionDecl; using clang::NamedDecl; @@ -210,6 +211,12 @@ string GetShortNameAsString(const clang::NamedDecl* named_decl) { ostream << *record_decl << "::"; } else if (const FunctionDecl *function_decl = DynCastFrom(*it)) { ostream << *function_decl << "::"; // could also add in '<< "()"' + } else if (const EnumDecl* enum_decl = DynCastFrom(*it)) { + if (enum_decl->isScoped()) { + ostream << *(cast<NamedDecl>(*it)) << "::"; + } else { + // Don't add a scope prefix for old-style unscoped enums. + } } else { ostream << *(cast<NamedDecl>(*it)) << "::"; } diff --git a/tests/cxx/badinc.cc b/tests/cxx/badinc.cc index 136d79b..755f72c 100644 --- a/tests/cxx/badinc.cc +++ b/tests/cxx/badinc.cc @@ -1945,9 +1945,9 @@ The full include-list for tests/cxx/badinc.cc: #include <new> // for operator new #include <string> // for basic_string, basic_string<>::iterator, operator+, string #include <typeinfo> // for type_info -#include "tests/cxx/badinc-d1.h" // for D1CopyClassFn, D1Function, D1_Class, D1_CopyClass, D1_Enum, D1_Enum::D11, D1_I1_Typedef, D1_StructPtr, D1_Subclass, D1_TemplateClass, D1_TemplateStructWithDefaultParam, MACRO_CALLING_I4_FUNCTION +#include "tests/cxx/badinc-d1.h" // for D11, D1CopyClassFn, D1Function, D1_Class, D1_CopyClass, D1_Enum, D1_I1_Typedef, D1_StructPtr, D1_Subclass, D1_TemplateClass, D1_TemplateStructWithDefaultParam, MACRO_CALLING_I4_FUNCTION #include "tests/cxx/badinc-d4.h" // for D4_ClassForOperator, operator<< -#include "tests/cxx/badinc-i1.h" // for EmptyDestructorClass, H_Class::H_Class_DefinedInI1, I1_And_I2_OverloadedFunction, I1_Base, I1_Class, I1_Class::NestedStruct, I1_ClassPtr, I1_Enum, I1_Enum::I11, I1_Enum::I12, I1_Enum::I13, I1_Function, I1_FunctionPtr, I1_I2_Class_Typedef, I1_MACRO_LOGGING_CLASS, I1_MACRO_SYMBOL_WITHOUT_VALUE, I1_MACRO_SYMBOL_WITH_VALUE, I1_MACRO_SYMBOL_WITH_VALUE0, I1_MACRO_SYMBOL_WITH_VALUE2, I1_ManyPtrStruct (ptr only), I1_MemberPtr, I1_NamespaceClass, I1_NamespaceStruct, I1_NamespaceTemplateFn, I1_OverloadedFunction, I1_PtrAndUseOnSameLine, I1_PtrDereferenceClass, I1_PtrDereferenceStatic, I1_PtrDereferenceStruct, I1_SiblingClass, I1_StaticMethod, I1_Struct, I1_Subclass, I1_SubclassesI2Class, I1_TemplateClass, I1_TemplateClass<>::I1_TemplateClass_int, I1_TemplateClassFwdDeclaredInD2 (ptr only), I1_TemplateFunction, I1_TemplateMethodOnlyClass, I1_TemplateSubclass, I1_Typedef, I1_TypedefOnly_Class, I1_TypedefOnly_Class<>::i, I1_Union, I1_UnnamedStruct, I1_UnusedNamespaceStruct (ptr only), I1_const_ptr, I2_OperatorDefinedInI1Class::operator<<, MACRO_CALLING_I6_FUNCTION, OperateOn, i1_GlobalFunction, i1_i1_classptr, i1_int, i1_int_global, i1_int_global2, i1_int_global2sub, i1_int_global3, i1_int_global3sub, i1_int_global4, i1_int_global4sub, i1_int_globalsub, i1_ns4, kI1ConstInt, operator== +#include "tests/cxx/badinc-i1.h" // for EmptyDestructorClass, H_Class::H_Class_DefinedInI1, I11, I12, I13, I1_And_I2_OverloadedFunction, I1_Base, I1_Class, I1_Class::NestedStruct, I1_ClassPtr, I1_Enum, I1_Function, I1_FunctionPtr, I1_I2_Class_Typedef, I1_MACRO_LOGGING_CLASS, I1_MACRO_SYMBOL_WITHOUT_VALUE, I1_MACRO_SYMBOL_WITH_VALUE, I1_MACRO_SYMBOL_WITH_VALUE0, I1_MACRO_SYMBOL_WITH_VALUE2, I1_ManyPtrStruct (ptr only), I1_MemberPtr, I1_NamespaceClass, I1_NamespaceStruct, I1_NamespaceTemplateFn, I1_OverloadedFunction, I1_PtrAndUseOnSameLine, I1_PtrDereferenceClass, I1_PtrDereferenceStatic, I1_PtrDereferenceStruct, I1_SiblingClass, I1_StaticMethod, I1_Struct, I1_Subclass, I1_SubclassesI2Class, I1_TemplateClass, I1_TemplateClass<>::I1_TemplateClass_int, I1_TemplateClassFwdDeclaredInD2 (ptr only), I1_TemplateFunction, I1_TemplateMethodOnlyClass, I1_TemplateSubclass, I1_Typedef, I1_TypedefOnly_Class, I1_TypedefOnly_Class<>::i, I1_Union, I1_UnnamedStruct, I1_UnusedNamespaceStruct (ptr only), I1_const_ptr, I2_OperatorDefinedInI1Class::operator<<, MACRO_CALLING_I6_FUNCTION, OperateOn, i1_GlobalFunction, i1_i1_classptr, i1_int, i1_int_global, i1_int_global2, i1_int_global2sub, i1_int_global3, i1_int_global3sub, i1_int_global4, i1_int_global4sub, i1_int_globalsub, i1_ns4, kI1ConstInt, operator== #include "tests/cxx/badinc2.c" class D2_Class; class D2_ForwardDeclareClass; diff --git a/tests/cxx/badinc.h b/tests/cxx/badinc.h index 8428bdf..e640927 100644 --- a/tests/cxx/badinc.h +++ b/tests/cxx/badinc.h @@ -393,9 +393,9 @@ The full include-list for tests/cxx/badinc.h: #include <set> // for set #include <string> // for string #include <vector> // for vector -#include "tests/cxx/badinc-d3.h" // for D3_Enum, D3_Enum::D31 +#include "tests/cxx/badinc-d3.h" // for D31, D3_Enum #include "tests/cxx/badinc-i2-inl.h" // for I2_Class::I2_Class, I2_Class::InlFileFn, I2_Class::InlFileStaticFn, I2_Class::InlFileTemplateFn, I2_Class::~I2_Class, I2_TemplateClass::I2_TemplateClass<FOO>, I2_TemplateClass::InlFileTemplateClassFn, I2_TemplateClass::~I2_TemplateClass<FOO> -#include "tests/cxx/badinc-i2.h" // for I2_Class, I2_Enum, I2_Enum::I21, I2_Enum::I22, I2_EnumForTypedefs, I2_MACRO, I2_Struct, I2_TemplateClass, I2_Typedef, I2_TypedefOnly_Class (ptr only), TemplateForHClassTplFn (ptr only) +#include "tests/cxx/badinc-i2.h" // for I21, I22, I2_Class, I2_Enum, I2_EnumForTypedefs, I2_MACRO, I2_Struct, I2_TemplateClass, I2_Typedef, I2_TypedefOnly_Class (ptr only), TemplateForHClassTplFn (ptr only) class Cc_Class; // lines XX-XX // TODO(csilvers): this should change to struct Cc_Struct. class Cc_Struct; // lines XX-XX |