Index: include/clang/Basic/DiagnosticGroups.td =================================================================== --- include/clang/Basic/DiagnosticGroups.td +++ include/clang/Basic/DiagnosticGroups.td @@ -687,7 +687,7 @@ // Aggregation warning settings. // Populate -Waddress with warnings from other groups. -def : DiagGroup<"address", [PointerBoolConversion, +def Address : DiagGroup<"address", [PointerBoolConversion, StringCompare, TautologicalPointerCompare]>; Index: include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- include/clang/Basic/DiagnosticSemaKinds.td +++ include/clang/Basic/DiagnosticSemaKinds.td @@ -6730,6 +6730,9 @@ def err_cannot_form_pointer_to_member_of_reference_type : Error< "cannot form a pointer-to-member to member %0 of reference type %1">; +def warn_taking_address_standard_library_function : Warning< + "taking the address of the standard library function '%0' is not allowed"> + , InGroup
; def err_incomplete_object_call : Error< "incomplete type in call to object of type %0">; Index: lib/Sema/SemaExpr.cpp =================================================================== --- lib/Sema/SemaExpr.cpp +++ lib/Sema/SemaExpr.cpp @@ -12048,8 +12048,11 @@ return MPTy; } } - } else if (!isa(dcl) && !isa(dcl) && - !isa(dcl)) + } else if (isa(dcl)) { + StringRef QualName = cast(dcl)->getQualifiedNameAsString(); + if (QualName.startswith("std::")) + Diag(OpLoc, diag::warn_taking_address_standard_library_function) << QualName; + } else if (!isa(dcl) && !isa(dcl)) llvm_unreachable("Unknown/unexpected decl type"); } Index: test/SemaCXX/warn_address_standard_library_function.cpp =================================================================== --- test/SemaCXX/warn_address_standard_library_function.cpp +++ test/SemaCXX/warn_address_standard_library_function.cpp @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -Waddress -std=c++14 %s +// RUN: %clang_cc1 -fsyntax-only -verify -Waddress -std=c++17 %s + +namespace std { + void terminate (void) { } +} + +namespace mystd { + void terminate (void) { } +} + +auto warn1(void) { + return &std::terminate; // expected-warning{{taking the address of the standard library function 'std::terminate' is not allowed}} +} + +auto warn2(void) { + return &(std::terminate); // expected-warning{{taking the address of the standard library function 'std::terminate' is not allowed}} +} + +auto nowarn1(void) { + return &mystd::terminate; +} + +auto nowarn2(void) { + return &(mystd::terminate); +}