summaryrefslogtreecommitdiffstats
path: root/clang/test/Sema/overloadable.c
Commit message (Collapse)AuthorAgeFilesLines
* [Sema] Deduplicate some availability checking logicErik Pilkington2019-03-201-6/+5
| | | | | | | | | | | | | | | Before this commit, we emit unavailable errors for calls to functions during overload resolution, and for references to all other declarations in DiagnoseUseOfDecl. The early checks during overload resolution aren't as good as the DiagnoseAvailabilityOfDecl based checks, as they error on the code from PR40991. This commit fixes this by removing the early checking. llvm.org/PR40991 rdar://48564179 Differential revision: https://reviews.llvm.org/D59394 llvm-svn: 356599
* [Sema] Allow unmarked overloadable functions.George Burgess IV2017-06-271-9/+91
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch extends the `overloadable` attribute to allow for one function with a given name to not be marked with the `overloadable` attribute. The overload without the `overloadable` attribute will not have its name mangled. So, the following code is now legal: void foo(void) __attribute__((overloadable)); void foo(int); void foo(float) __attribute__((overloadable)); In addition, this patch fixes a bug where we'd accept code with `__attribute__((overloadable))` inconsistently applied. In other words, we used to accept: void foo(void); void foo(void) __attribute__((overloadable)); But we will do this no longer, since it defeats the original purpose of requiring `__attribute__((overloadable))` on all redeclarations of a function. This breakage seems to not be an issue in practice, since the only code I could find that had this pattern often looked like: void foo(void); void foo(void) __attribute__((overloadable)) __asm__("foo"); void foo(int) __attribute__((overloadable)); ...Which can now be simplified by simply removing the asm label and overloadable attribute from the redeclaration of `void foo(void);` Differential Revision: https://reviews.llvm.org/D32332 llvm-svn: 306467
* [test] Make absolute line numbers relative; NFCGeorge Burgess IV2017-06-211-10/+10
| | | | | | | Done to remove noise from https://reviews.llvm.org/D32332 (and to make this test more resilient to changes in general). llvm-svn: 305947
* [Sema] Make typeof(OverloadedFunctionName) not a pointer.George Burgess IV2017-05-091-0/+15
| | | | | | | | | | | | | | | | We were sometimes doing a function->pointer conversion in Sema::CheckPlaceholderExpr, which isn't the job of CheckPlaceholderExpr. So, when we saw typeof(OverloadedFunctionName), where OverloadedFunctionName referenced a name with only one function that could have its address taken, we'd give back a function pointer type instead of a function type. This is incorrect. I kept the logic for doing the function pointer conversion in resolveAndFixAddressOfOnlyViableOverloadCandidate because it was more consistent with existing ResolveAndFix* methods. llvm-svn: 302506
* [Sema] Relax overloading restrictions in C.George Burgess IV2016-09-021-1/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch allows us to perform incompatible pointer conversions when resolving overloads in C. So, the following code will no longer fail to compile (though it will still emit warnings, assuming the user hasn't opted out of them): ``` void foo(char *) __attribute__((overloadable)); void foo(int) __attribute__((overloadable)); void callFoo() { unsigned char bar[128]; foo(bar); // selects the char* overload. } ``` These conversions are ranked below all others, so: A. Any other viable conversion will win out B. If we had another incompatible pointer conversion in the example above (e.g. `void foo(int *)`), we would complain about an ambiguity. Differential Revision: https://reviews.llvm.org/D24113 llvm-svn: 280553
* [Sema] Create a separate group for incompatible function pointer warningBruno Cardoso Lopes2016-07-181-1/+1
| | | | | | | | | | | | | Give incompatible function pointer warning its own diagnostic group but still leave it as a subgroup of incompatible-pointer-types. This is in preparation to promote -Wincompatible-function-pointer-types to error on darwin. Differential Revision: https://reviews.llvm.org/D22248 rdar://problem/12907612 llvm-svn: 275907
* [Sema] Allow implicit conversions of &overloaded_fn in C.George Burgess IV2016-03-231-1/+24
| | | | | | | | | | | | | | | | | | | | | | | Also includes a minor ``enable_if`` docs update. Currently, our address-of overload machinery will only allow implicit conversions of overloaded functions to void* in C. For example: ``` void f(int) __attribute__((overloadable)); void f(double) __attribute__((overloadable, enable_if(0, ""))); void *fp = f; // OK. This is C and the target is void*. void (*fp2)(void) = f; // Error. This is C, but the target isn't void*. ``` This patch makes the assignment of `fp2` select the `f(int)` overload, rather than emitting an error (N.B. you'll still get a warning about the `fp2` assignment if you use -Wincompatible-pointer-types). Differential Revision: http://reviews.llvm.org/D13704 llvm-svn: 264132
* [Sema] Allow C conversions in C overload logicGeorge Burgess IV2015-10-111-0/+14
| | | | | | | | | | C allows for some implicit conversions that C++ does not, e.g. void* -> char*. This patch teaches clang that these conversions are okay when dealing with overloads in C. Differential Revision: http://reviews.llvm.org/D13604 llvm-svn: 249995
* Replacing a custom diagnostic with a more standard one. No functional change ↵Aaron Ballman2013-11-261-1/+1
| | | | | | intended. llvm-svn: 195770
* Added the attribute name to the err_attribute_wrong_number_arguments ↵Aaron Ballman2013-07-231-2/+2
| | | | | | | | diagnostic for clarity; updated almost all of the affected test cases. Thanks to Fariborz Jahanian for the suggestion! llvm-svn: 186980
* Correcting the NSObject and Overloadable attribute diagnostics so that the ↵Aaron Ballman2013-07-231-0/+1
| | | | | | count reported matches reality. llvm-svn: 186936
* Reinstate r185229, reverted in r185256, with a tweak: further ignore theRichard Smith2013-06-301-0/+15
| | | | | | | | | | | | | | | | | | | | | | | standard's rule that an extern "C" declaration conflicts with any entity in the global scope with the same name. Now we only care if the global scope entity is a variable declaration (and so might have the same mangled name as the extern "C" declaration). This has been reported as a standard defect. Original commit message: PR7927, PR16247: Reimplement handling of matching extern "C" declarations across scopes. When we declare an extern "C" name that is not a redeclaration of an entity in the same scope, check whether it redeclares some extern "C" entity from another scope, and if not, check whether it conflicts with a (non-extern-"C") entity in the translation unit. When we declare a name in the translation unit that is not a redeclaration, check whether it conflicts with any extern "C" entities (possibly from other scopes). llvm-svn: 185281
* Revert r185229 as it breaks compilation of <windows.h>Timur Iskhodzhanov2013-06-291-15/+0
| | | | llvm-svn: 185256
* PR7927, PR16247: Reimplement handling of matching extern "C" declarationsRichard Smith2013-06-281-0/+15
| | | | | | | | | | | | | | | across scopes. When we declare an extern "C" name that is not a redeclaration of an entity in the same scope, check whether it redeclares some extern "C" entity from another scope, and if not, check whether it conflicts with a (non-extern-"C") entity in the translation unit. When we declare a name in the translation unit that is not a redeclaration, check whether it conflicts with any extern "C" entities (possibly from other scopes). llvm-svn: 185229
* Modify how the -verify flag works. Currently, the verification string andRichard Trieu2011-12-151-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | diagnostic message are compared. If either is a substring of the other, then no error is given. This gives rise to an unexpected case: // expect-error{{candidate function has different number of parameters}} will match the following error messages from Clang: candidate function has different number of parameters (expected 1 but has 2) candidate function has different number of parameters It will also match these other error messages: candidate function function has different number of parameters number of parameters This patch will change so that the verification string must be a substring of the diagnostic message before accepting. Also, all the failing tests from this change have been corrected. Some stats from this cleanup: 87 - removed extra spaces around verification strings 70 - wording updates to diagnostics 40 - extra leading or trailing characters (typos, unmatched parens or quotes) 35 - diagnostic level was included (error:, warning:, or note:) 18 - flag name put in the warning (-Wprotocol) llvm-svn: 146619
* Make sure that we diagnose attribute((overloadable)) functions withoutDouglas Gregor2010-08-061-1/+10
| | | | | | prototypes. Fixes PR7738. llvm-svn: 110443
* Check compatibility of vector types using their canonicalizations.John McCall2010-03-121-1/+10
| | | | | | | | | Fixes an assertion arising C overload analysis, but really I can't imagine that this wouldn't cause a thousand other uncaught failures. Fixes PR6600. llvm-svn: 98400
* Change the printing of OR_Deleted overload results to print all the candidates,John McCall2010-01-081-3/+3
| | | | | | | | | | | | | | | not just the viable ones. This is reasonable because the most common use of deleted functions is to exclude some implicit conversion during calls; users therefore will want to figure out why some other options were excluded. Started sorting overload results. Right now it just sorts by location in the translation unit (after putting viable functions first), but we can do better than that. Changed bool OnlyViable parameter to PrintOverloadCandidates to an enum for better self-documentation. llvm-svn: 92990
* Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'.Daniel Dunbar2009-12-151-1/+1
| | | | | | | | | - This is designed to make it obvious that %clang_cc1 is a "test variable" which is substituted. It is '%clang_cc1' instead of '%clang -cc1' because it can be useful to redefine what gets run as 'clang -cc1' (for example, to set a default target). llvm-svn: 91446
* Rename clang to clang-cc.Daniel Dunbar2009-03-241-1/+1
| | | | | | Tests and drivers updated, still need to shuffle dirs. llvm-svn: 67602
* Downgrade complaints about calling unavailable functions to a warningDouglas Gregor2009-02-181-2/+2
| | | | | | | | | | | | | | | | | | (as GCC does), except when we've performed overload resolution and found an unavailable function: in this case, we actually error. Merge the checking of unavailable functions with the checking for deprecated functions. This unifies a bit of code, and makes sure that we're checking for unavailable functions in the right places. Also, this check can cause an error. We may, eventually, want an option to make "unavailable" warnings into errors. Implement much of the logic needed for C++0x deleted functions, which are effectively the same as "unavailable" functions (but always cause an error when referenced). However, we don't have the syntax to specify deleted functions yet :) llvm-svn: 64955
* Allow "overloadable" functions in C to be declared as variadic withoutDouglas Gregor2009-02-181-0/+3
| | | | | | | | | | | | | | | any named parameters, e.g., this is accepted in C: void f(...) __attribute__((overloadable)); although this would be rejected: void f(...); To do this, moved the checking of the "ellipsis without any named arguments" condition from the parser into Sema (where it belongs anyway). llvm-svn: 64902
* Don't allow calls to functions marked "unavailable". There's more workDouglas Gregor2009-02-181-0/+10
| | | | | | | | | | to do in this area, since there are other places that reference FunctionDecls. Don't allow "overloadable" functions (in C) to be declared without a prototype. llvm-svn: 64897
* Proof that attribute __overloadable__ works as well as overloadableDouglas Gregor2009-02-171-1/+1
| | | | llvm-svn: 64781
* Tighten checking of the "overloadable" attribute. If any function by aDouglas Gregor2009-02-131-2/+5
| | | | | | | | | | | | | | | | | | | given name in a given scope is marked as "overloadable", every function declaration and definition with that same name and in that same scope needs to have the "overloadable" attribute. Essentially, the "overloadable" attribute is not part of attribute merging, so it must be specified even for redeclarations. This keeps users from trying to be too sneaky for their own good: double sin(double) __attribute__((overloadable)); // too sneaky #include <math.h> Previously, this would have made "sin" overloadable, and therefore given it a mangled name. Now, we get an error inside math.h when we see a (re)declaration of "sin" that doesn't have the "overloadable" attribute. llvm-svn: 64414
* Add missing test for the "overloadable" attributeDouglas Gregor2009-02-121-0/+37
llvm-svn: 64396
OpenPOWER on IntegriCloud