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 @@ -11934,7 +11934,6 @@ Expr::LValueClassification lval = op->ClassifyLValue(Context); unsigned AddressOfError = AO_No_Error; - if (lval == Expr::LV_ClassTemporary || lval == Expr::LV_ArrayTemporary) { bool sfinae = (bool)isSFINAEContext(); Diag(OpLoc, isSFINAEContext() ? diag::err_typecheck_addrof_temporary @@ -12048,8 +12047,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 foo (void) { } +} + +namespace mystd { + void foo (void) { } +} + +auto warn1(void) { + return &std::foo; // expected-warning{{taking the address of the standard library function 'std::foo' is not allowed}} +} + +auto warn2(void) { + return &(std::foo); // expected-warning{{taking the address of the standard library function 'std::foo' is not allowed}} +} + +auto nowarn1(void) { + return &mystd::foo; +} + +auto nowarn2(void) { + return &(mystd::foo); +}