diff options
author | George Burgess IV <george.burgess.iv@gmail.com> | 2015-10-12 19:57:04 +0000 |
---|---|---|
committer | George Burgess IV <george.burgess.iv@gmail.com> | 2015-10-12 19:57:04 +0000 |
commit | 5f21c718007fdc3b801690ef96908b43b8a1924e (patch) | |
tree | ec62116b246a319fd019f1f1545b620ec919cf3e /clang/lib/Sema/SemaCast.cpp | |
parent | 3320bcd81569bcf9dc73b02bfc6b08352ab4cf22 (diff) | |
download | llvm-5f21c718007fdc3b801690ef96908b43b8a1924e.zip llvm-5f21c718007fdc3b801690ef96908b43b8a1924e.tar.gz llvm-5f21c718007fdc3b801690ef96908b43b8a1924e.tar.bz2 |
[Sema] Make `&function_with_enable_if_attrs` an error
This fixes a bug where one can take the address of a conditionally
enabled function to drop its enable_if guards. For example:
int foo(int a) __attribute__((enable_if(a > 0, "")));
int (*p)(int) = &foo;
int result = p(-1); // compilation succeeds; calls foo(-1)
Overloading logic has been updated to reflect this change, as well.
Functions with enable_if attributes that are always true are still
allowed to have their address taken.
Differential Revision: http://reviews.llvm.org/D13607
llvm-svn: 250090
Diffstat (limited to 'clang/lib/Sema/SemaCast.cpp')
-rw-r--r-- | clang/lib/Sema/SemaCast.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp index d87be3b..5099867 100644 --- a/clang/lib/Sema/SemaCast.cpp +++ b/clang/lib/Sema/SemaCast.cpp @@ -2236,6 +2236,16 @@ void CastOperation::CheckCStyleCast() { return; } + // Overloads are allowed with C extensions, so we need to support them. + if (SrcExpr.get()->getType() == Self.Context.OverloadTy) { + DeclAccessPair DAP; + if (FunctionDecl *FD = Self.ResolveAddressOfOverloadedFunction( + SrcExpr.get(), DestType, /*Complain=*/true, DAP)) + SrcExpr = Self.FixOverloadedFunctionReference(SrcExpr.get(), DAP, FD); + else + return; + assert(SrcExpr.isUsable()); + } SrcExpr = Self.DefaultFunctionArrayLvalueConversion(SrcExpr.get()); if (SrcExpr.isInvalid()) return; |