Index: clang-tidy/google/ExplicitConstructorCheck.cpp =================================================================== --- clang-tidy/google/ExplicitConstructorCheck.cpp +++ clang-tidy/google/ExplicitConstructorCheck.cpp @@ -49,14 +49,16 @@ } bool isStdInitializerList(QualType Type) { - if (const RecordType *RT = Type.getCanonicalType()->getAs()) { - if (ClassTemplateSpecializationDecl *Specialization = + Type = Type.getCanonicalType(); + if (const auto *TS = Type->getAs()) { + if (const TemplateDecl *TD = TS->getTemplateName().getAsTemplateDecl()) + return TD->getName() == "initializer_list"; + } + if (const auto *RT = Type->getAs()) { + if (auto *Specialization = dyn_cast(RT->getDecl())) { ClassTemplateDecl *Template = Specialization->getSpecializedTemplate(); - // First use the fast getName() method to avoid unnecessary calls to the - // slow getQualifiedNameAsString(). - return Template->getName() == "initializer_list" && - Template->getQualifiedNameAsString() == "std::initializer_list"; + return Template->getName() == "initializer_list"; } } return false; Index: test/clang-tidy/google-explicit-constructor.cpp =================================================================== --- test/clang-tidy/google-explicit-constructor.cpp +++ test/clang-tidy/google-explicit-constructor.cpp @@ -63,11 +63,11 @@ // CHECK-FIXES: {{^ }}B(::std::initializer_list list4) {} explicit B(const ::std::initializer_list &list5) {} - // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: initializer-list constructor should not be declared explicit [google-explicit-constructor] + // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: initializer-list constructor should not be declared explicit // CHECK-FIXES: {{^ }}B(const ::std::initializer_list &list5) {} explicit B(::std::initializer_list &&list6) {} - // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: initializer-list constructor should not be declared explicit [google-explicit-constructor] + // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: initializer-list constructor should not be declared explicit // CHECK-FIXES: {{^ }}B(::std::initializer_list &&list6) {} }; @@ -79,6 +79,24 @@ C(initializer_list &&list3) {} }; +template +struct C2 { + C2(initializer_list list1) {} + C2(const initializer_list &list2) {} + C2(initializer_list &&list3) {} + + explicit C2(initializer_list list4) {} + // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: initializer-list constructor should not be declared explicit + // CHECK-FIXES: {{^ }}C2(initializer_list list4) {} +}; + +template +struct C3 { + C3(initializer_list list1) {} + C3(const std::initializer_list &list2) {} + C3(::std::initializer_list &&list3) {} +}; + struct D { template explicit D(T t) {} @@ -86,6 +104,10 @@ template struct E { + E(T *pt) {} + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: single-argument constructors must be explicit + // CHECK-FIXES: {{^ }}explicit E(T *pt) {} + explicit E(T t) {} template explicit E(U u) {} @@ -96,3 +118,4 @@ E e(list); E e2(list); } +