summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaOverload.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Deprecated (legacy) string literal conversion to 'char *' causes strange ↵Dmitry Polukhin2016-07-191-2/+0
| | | | | | | | | | | | | | overloading resolution It's a patch for PR28050. Seems like overloading resolution wipes out the first standard conversion sequence (before user-defined conversion) in case of deprecated string literal conversion. Differential revision: https://reviews.llvm.org/D21228 Patch by Alexander Makarov llvm-svn: 275970
* [CUDA] Don't assume that destructors can't be overloaded.Justin Lebar2016-07-121-2/+1
| | | | | | | | | | | | | | | Summary: You can overload a destructor in CUDA, and SemaOverload needs to be tweaked not to crash when it sees an explicit call to an overloaded destructor. Reviewers: rsmith Subscribers: cfe-commits, tra Differential Revision: http://reviews.llvm.org/D21912 llvm-svn: 275231
* [MS ABI] Pick an inheritance model if we resolve an overload setDavid Majnemer2016-06-301-0/+3
| | | | | | | | | | | | | We didn't assign an inheritance model for 'Foo' if the event an exrepssion like '&Foo::Bar' occured if 'Bar' could resolve to multiple functions. Once the overload set is resolved to a particular member, we enforce a specific inheritance model. This fixes PR28360. llvm-svn: 274202
* P0136R1, DR1573, DR1645, DR1715, DR1736, DR1903, DR1941, DR1959, DR1991:Richard Smith2016-06-281-43/+64
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Replace inheriting constructors implementation with new approach, voted into C++ last year as a DR against C++11. Instead of synthesizing a set of derived class constructors for each inherited base class constructor, we make the constructors of the base class visible to constructor lookup in the derived class, using the normal rules for using-declarations. For constructors, UsingShadowDecl now has a ConstructorUsingShadowDecl derived class that tracks the requisite additional information. We create shadow constructors (not found by name lookup) in the derived class to model the actual initialization, and have a new expression node, CXXInheritedCtorInitExpr, to model the initialization of a base class from such a constructor. (This initialization is special because it performs real perfect forwarding of arguments.) In cases where argument forwarding is not possible (for inalloca calls, variadic calls, and calls with callee parameter cleanup), the shadow inheriting constructor is not emitted and instead we directly emit the initialization code into the caller of the inherited constructor. Note that this new model is not perfectly compatible with the old model in some corner cases. In particular: * if B inherits a private constructor from A, and C uses that constructor to construct a B, then we previously required that A befriends B and B befriends C, but the new rules require A to befriend C directly, and * if a derived class has its own constructors (and so its implicit default constructor is suppressed), it may still inherit a default constructor from a base class llvm-svn: 274049
* Use even more ArrayRefsDavid Majnemer2016-06-241-4/+4
| | | | | | No functional change is intended, just a small refactoring. llvm-svn: 273650
* [Sema] Teach CheckPlaceholderExpr about unaddressable functions.George Burgess IV2016-06-081-0/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Given the following C++: ``` void foo(); void foo() __attribute__((enable_if(false, ""))); bool bar() { auto P = foo; return P == foo; } ``` We'll currently happily (and correctly) resolve `foo` to the `foo` overload without `enable_if` when assigning to `P`. However, we'll complain about an ambiguous overload on the `P == foo` line, because `Sema::CheckPlaceholderExpr` doesn't recognize that there's only one `foo` that could possibly work here. This patch teaches `Sema::CheckPlaceholderExpr` how to properly deal with such cases. Grepping for other callers of things like `Sema::ResolveAndFixSingleFunctionTemplateSpecialization`, it *looks* like this is the last place that needed to be fixed up. If I'm wrong, I'll see if there's something we can do that beats what amounts to whack-a-mole with bugs. llvm-svn: 272080
* Preserve the FoundDecl when performing overload resolution for constructors.Richard Smith2016-05-111-80/+66
| | | | | | | | | This is in preparation for C++ P0136R1, which switches the model for inheriting constructors over from synthesizing a constructor to finding base class constructors (via using shadow decls) when looking for derived class constructors. llvm-svn: 269231
* [MSVC] Implementation of __unaligned as a proper type qualifierAndrey Bokhanko2016-05-111-1/+21
| | | | | | | | | | | This patch implements __unaligned (MS extension) as a proper type qualifier (before that, it was implemented as an ignored attribute). It also fixes PR27367 and PR27666. Differential Revision: http://reviews.llvm.org/D20103 llvm-svn: 269220
* [Sema] Fix value-dependent enable_if bug.George Burgess IV2016-05-111-13/+6
| | | | | | | | | | | | | | | This patch fixes a bug where we would assume all value-dependent enable_if conditions give successful results. Instead, we consider value-dependent enable_if conditions to always fail. While this isn't ideal, this is the best we can realistically do without changing both enable_if's semantics and large parts of Sema (specifically, all of the parts that don't expect type dependence to come out of nowhere, and that may interact with overload resolution). Differential Revision: http://reviews.llvm.org/D20130 llvm-svn: 269154
* [Sema] Fix an overload resolution bug with enable_if.George Burgess IV2016-05-101-21/+37
| | | | | | | | | | | | | | | | | | | | | | Currently, if clang::isBetterOverloadCandidate encounters an enable_if attribute on either candidate that it's inspecting, it will ignore all lower priority attributes (e.g. pass_object_size). This is problematic in cases like: ``` void foo(char *c) __attribute__((enable_if(1, ""))); void foo(char *c __attribute__((pass_object_size(0)))) __attribute__((enable_if(1, ""))); ``` ...Because we would ignore the pass_object_size attribute in the second `foo`, and consider any call to `foo` to be ambiguous. This patch makes overload resolution consult further tiebreakers (e.g. pass_object_size) if two candidates have equally good enable_if attributes. llvm-svn: 269005
* Enable support for __float128 in Clang and enable it on pertinent platformsNemanja Ivanovic2016-05-091-7/+23
| | | | | | | | | | | | | | | | | | This patch corresponds to reviews: http://reviews.llvm.org/D15120 http://reviews.llvm.org/D19125 It adds support for the __float128 keyword, literals and target feature to enable it. Based on the latter of the two aforementioned reviews, this feature is enabled on Linux on i386/X86 as well as SystemZ. This is also the second attempt in commiting this feature. The first attempt did not enable it on required platforms which caused failures when compiling type_traits with -std=gnu++11. If you see failures with compiling this header on your platform after this commit, it is likely that your platform needs to have this feature enabled. llvm-svn: 268898
* Revert r268727, it caused PR27666.Nico Weber2016-05-061-4/+0
| | | | llvm-svn: 268736
* [MSVC] Implementation of __unaligned as a proper type qualifierAndrey Bokhanko2016-05-061-0/+4
| | | | | | | | | | | This patch implements __unaligned (MS extension) as a proper type qualifier (before that, it was implemented as an ignored attribute). It also fixes PR27367. Differential Revision: http://reviews.llvm.org/D19654 llvm-svn: 268727
* [Sema] Specify the underlying type for an enum. NFC.George Burgess IV2016-04-291-1/+1
| | | | llvm-svn: 268113
* Warn if function or variable cannot be implicitly instantiatedSerge Pavlov2016-04-191-5/+2
| | | | | | | | | | | | With this patch compiler emits warning if it tries to make implicit instantiation of a template but cannot find the template definition. The warning can be suppressed by explicit instantiation declaration or by command line options -Wundefined-var-template and -Wundefined-func-template. The implementation follows the discussion of http://reviews.llvm.org/D12326. Differential Revision: http://reviews.llvm.org/D16396 llvm-svn: 266719
* Revert 266186 as it breaks anything that includes type_traits on some platformsNemanja Ivanovic2016-04-151-23/+7
| | | | | | | | | | Since this patch provided support for the __float128 type but disabled it on all platforms by default, some platforms can't compile type_traits with -std=gnu++11 since there is a specialization with __float128. This reverts the patch until D19125 is approved (i.e. we know which platforms need this support enabled). llvm-svn: 266460
* Enable support for __float128 in ClangNemanja Ivanovic2016-04-131-7/+23
| | | | | | | | | | | | | | | | This patch corresponds to review: http://reviews.llvm.org/D15120 It adds support for the __float128 keyword, literals and a target feature to enable it. This support is disabled by default on all targets and any target that has support for this type is free to add it. Based on feedback that I've received from target maintainers, this appears to be the right thing for most targets. I have not heard from the maintainers of X86 which I believe supports this type. I will subsequently investigate the impact of enabling this on X86. llvm-svn: 266186
* Remove redundant conditions of the form (A || (!A && B)) -> (A || B)Benjamin Kramer2016-04-111-2/+1
| | | | | | Found by cppcheck! PR27286 PR27287 PR27288 PR27289 llvm-svn: 265918
* NFC: simplify code in BuildInstanceMessage.Manman Ren2016-04-071-5/+5
| | | | | | | | | | | | | | | | Instead of searching the global pool multiple times: in LookupFactoryMethodInGlobalPool, LookupInstanceMethodInGlobalPool, CollectMultipleMethodsInGlobalPool, and AreMultipleMethodsInGlobalPool, we now collect the method candidates in CollectMultipleMethodsInGlobalPool only, and other functions will use the collected method set. This commit adds parameter "Methods" to AreMultipleMethodsInGlobalPool, and SelectBestMethod. It also changes the implementation of CollectMultipleMethodsInGlobalPool to collect the desired kind first, if none is found, to collect the other kind. This avoids the need to call both LookupFactoryMethodInGlobalPool and LookupInstanceMethodInGlobalPool. llvm-svn: 265711
* [CUDA] Make unattributed constexpr functions implicitly host+device.Justin Lebar2016-03-301-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | With this patch, by a constexpr function is implicitly host+device unless: a) it's a variadic function (variadic functions are not allowed on the device side), or b) it's preceeded by a __device__ overload in a system header. The restriction on overloading __host__ __device__ functions on the basis of their CUDA attributes remains in place, but we use (b) to allow us to define __device__ overloads for constexpr functions in cmath, which would otherwise be __host__ __device__ and thus not overloadable. You can disable this behavior with -fno-cuda-host-device-constexpr. Reviewers: tra, rnk, rsmith Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D18380 llvm-svn: 264964
* [Sema] s/UseUsingDeclRules/UseMemberUsingDeclRules/Justin Lebar2016-03-301-3/+3
| | | | | | | | | | | | | | | Summary: IsOverload has a param named UseUsingDeclRules. But as far as I can tell, it should be called UseMemberUsingDeclRules. That is, it only applies to "using" declarations inside classes or structs. Reviewers: rsmith Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D18538 llvm-svn: 264920
* [CUDA] Remove three obsolete CUDA cc1 flags.Justin Lebar2016-03-291-6/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: * -fcuda-target-overloads Previously unconditionally set to true by the driver. Necessary for correct functioning of the compiler -- our CUDA headers wrapper won't compile without this. * -fcuda-disable-target-call-checks Previously unconditionally set to true by the driver. Necessary to compile almost any external CUDA code -- almost all libraries assume that host+device code can call host or device functions. * -fcuda-allow-host-calls-from-host-device No effect when target overloading is enabled. Reviewers: tra Subscribers: rsmith, cfe-commits Differential Revision: http://reviews.llvm.org/D18416 llvm-svn: 264739
* P0138R2: Allow direct-list-initialization of an enumeration from an integralRichard Smith2016-03-281-0/+7
| | | | | | value that can convert to the enum's underlying type. llvm-svn: 264564
* Fix nondeterminism in computation of builtin operator overload sets.Richard Smith2016-03-251-3/+4
| | | | llvm-svn: 264363
* [Sema] Allow implicit conversions of &overloaded_fn in C.George Burgess IV2016-03-231-11/+20
| | | | | | | | | | | | | | | | | | | | | | | 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 casting of some overloaded functionsGeorge Burgess IV2016-03-191-1/+37
| | | | | | | | | | | Some functions can't have their address taken. If we encounter an overload set where only one of the candidates can have its address taken, we should automatically select that candidate in cast expressions. Differential Revision: http://reviews.llvm.org/D17701 llvm-svn: 263887
* Sema: Methods in unavailable classes are unavailableDuncan P. N. Exon Smith2016-03-081-1/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Similar to the template cases in r262050, when a C++ method in an unavailable struct/class calls unavailable API, don't diagnose an error. I.e., this case was failing: void foo() __attribute__((unavailable)); struct __attribute__((unavailable)) A { void bar() { foo(); } }; Since A is unavailable, A::bar is allowed to call foo. However, we were emitting a diagnostic here. This commit checks up the context chain from A::bar, in a manner inspired by SemaDeclAttr.cpp:isDeclUnavailable. I expected to find other related issues but failed to trigger them: - I wondered if DeclBase::getAvailability should check for `TemplateDecl` instead of `FunctionTemplateDecl`, but I couldn't find a way to trigger this. I left behind a few extra tests to make sure we don't regress. - I wondered if Sema::isFunctionConsideredUnavailable should be symmetric, checking up the context chain of the callee (this commit only checks up the context chain of the caller). However, I couldn't think of a testcase that didn't require first referencing the unavailable type; this, we already diagnose. rdar://problem/25030656 llvm-svn: 262921
* PR5941 - improve diagnostic for * vs & confusion when choosing overload ↵David Blaikie2016-03-041-1/+4
| | | | | | | | | | candidate with a parameter of incomplete (ref or pointer) type Reviewers: dblaikie Differential Revision: http://reviews.llvm.org/D16949 llvm-svn: 262752
* Generalize the consumed-parameter array on FunctionProtoTypeJohn McCall2016-03-011-3/+2
| | | | | | | | | to allow arbitrary data to be associated with a parameter. Also, fix a bug where we apparently haven't been serializing this information for the last N years. llvm-svn: 262278
* Minor cleanup of Sema::CheckEnableIf. NFC.George Burgess IV2016-02-241-23/+16
| | | | llvm-svn: 261798
* [CUDA] do not allow attribute-based overloading for __global__ functions.Artem Belevich2016-02-241-1/+4
| | | | | | | | __global__ functions are present on both host and device side, so providing __host__ or __device__ overloads is not going to do anything useful. llvm-svn: 261778
* Remove use of builtin comma operator.Richard Trieu2016-02-181-2/+4
| | | | | | Cleanup for upcoming Clang warning -Wcomma. No functionality change intended. llvm-svn: 261271
* [CUDA] Tweak attribute-based overload resolution to match nvcc behavior.Artem Belevich2016-02-121-3/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | This is an artefact of split-mode CUDA compilation that we need to mimic. HD functions are sometimes allowed to call H or D functions. Due to split compilation mode device-side compilation will not see host-only function and thus they will not be considered at all. For clang both H and D variants will become function overloads visible to compiler. Normally target attribute is considered only if C++ rules can not determine which function is better. However in this case we need to ignore functions that would not be present during current compilation phase before we apply normal overload resolution rules. Changes: * introduced another level of call preference to better describe possible call combinations. * removed WrongSide functions from consideration if the set contains SameSide function. * disabled H->D, D->H and G->H calls. These combinations are not allowed by CUDA and we were reluctantly allowing them to work around device-side calls to math functions in std namespace. We no longer need it after r258880. Differential Revision: http://reviews.llvm.org/D16870 llvm-svn: 260697
* Make ParentMap work with explicit specializations of function templates.Nico Weber2016-02-081-1/+0
| | | | | | | | | | | | | | | | | For an explicit specialization, we first build a FunctionDecl, and then we call SubstDecl() on it to build a second FunctionDecl, which has the first FunctionDecl as canonical decl. The address of an explicit specialization of function template used to be the canonical decl of the FunctionDecl. This is different from all the other DeduceTemplateArguments() calls in SemaOverload, and since the canonical decl isn't visited by ParentMap while the redecl is, it also made ParentMap assert when computing the parent of a address-of-explicit-specialization-fun-template. To fix, remove the getCanonicalDecl() call. No behavior difference for clang, but it fixes an assert in ParentMap (which is e.g. used by libTooling). llvm-svn: 260159
* Annotate dump() methods with LLVM_DUMP_METHOD, addressing Richard Smith ↵Yaron Keren2016-01-291-1/+1
| | | | | | r259192 post commit comment. llvm-svn: 259232
* Make -Wdelete-non-virtual-dtor warn on explicit `a->~A()` dtor calls too.Nico Weber2016-01-151-0/+11
| | | | | | | | | | | | | | | | | | | | | | | -Wdelete-non-virtual-dtor warns if A is a type with virtual functions but without virtual dtor has its constructor called via `delete a`. This makes the warning also fire if the dtor is called via `a->~A()`. This would've found a security bug in Chromium at compile time. Fixes PR26137. To fix the warning, add a virtual destructor, make the class final, or remove its other virtual methods. If you want to silence the warning, there's also a fixit that shows how: test.cc:12:3: warning: destructor called on 'B' ... [-Wdelete-non-virtual-dtor] b->~B(); ^ test.cc:12:6: note: qualify call to silence this warning b->~B(); ^ B:: http://reviews.llvm.org/D16206 llvm-svn: 257939
* [Sema] Suppress diags in overload resolution.George Burgess IV2016-01-131-9/+16
| | | | | | | | | | We were emitting diagnostics from our shiny new C-only overload resolution mode. This patch attempts to silence all such diagnostics. This fixes PR26085. Differential Revision: http://reviews.llvm.org/D16159 llvm-svn: 257710
* [Bugfix] Fix ICE on constexpr vector splat.George Burgess IV2016-01-131-0/+1
| | | | | | | | | | | | | In {CG,}ExprConstant.cpp, we weren't treating vector splats properly. This patch makes us treat splats more properly. Additionally, this patch adds a new cast kind which allows a bool->int cast to result in -1 or 0, instead of 1 or 0 (for true and false, respectively), so we can sanely model OpenCL bool->int casts in the AST. Differential Revision: http://reviews.llvm.org/D14877 llvm-svn: 257559
* [Sema] Teach overload resolution about unaddressable functions.George Burgess IV2016-01-071-1/+25
| | | | | | | | | | | | Given an expression like `(&Foo)();`, we perform overload resolution as if we are calling `Foo` directly. This causes problems if `Foo` is a function that can't have its address taken. This patch teaches overload resolution to ignore functions that can't have their address taken in such cases. Differential Revision: http://reviews.llvm.org/D15590 llvm-svn: 257016
* Improve diagnostic for the case where a function template candidate is rejectedRichard Smith2015-12-311-4/+52
| | | | | | | | by overload resolution because deduction succeeds, but the substituted parameter type for some parameter (with deduced type) doesn't exactly match the corresponding adjusted argument type. llvm-svn: 256657
* [TrailingObjects] Convert ASTTemplateKWAndArgsInfo and ↵James Y Knight2015-12-241-2/+2
| | | | | | | | | | | | | | | | | | | ASTTemplateArgumentListInfo. Doing so required separating them so that the former doesn't inherit from the latter anymore. Investigating that, it became clear that the inheritance wasn't actually providing real value in any case. So also: - Remove a bunch of redundant functions (getExplicitTemplateArgs, getOptionalExplicitTemplateArgs) on various Expr subclasses which depended on the inheritance relationship. - Switched external callers to use pre-existing accessors that return the data they're actually interested in (getTemplateArgs, getNumTemplateArgs, etc). - Switched internal callers to use pre-existing getTemplateKWAndArgsInfo. llvm-svn: 256359
* Split RequireCompleteType into a function that actually requires that the typeRichard Smith2015-12-181-12/+13
| | | | | | | | | | | | | | | | | | | is complete (with an error produced if not) and a function that merely queries whether the type is complete. Either way we'll trigger instantiation if necessary, but only the former will diagnose and recover from missing module imports. The intent of this change is to prevent a class of bugs where code would call RequireCompleteType(..., 0) and then ignore the result. With modules, we must check the return value and use it to determine whether the definition of the type is visible. This also fixes a debug info quality issue: calls to isCompleteType do not trigger the emission of debug information for a type in limited-debug-info mode. This allows us to avoid emitting debug information for type definitions in more cases where we believe it is safe to do so. llvm-svn: 256049
* [modules] Don't try to use the definition of a class ifRichard Smith2015-12-181-6/+3
| | | | | | | RequireCompleteType(..., 0) says we're not permitted to do so. The definition might not be visible, even though we know what it is. llvm-svn: 256045
* Wire a SourceLocation into IsDerivedFrom and move the RequireCompleteType callRichard Smith2015-12-181-59/+61
| | | | | | | | for the derived class into it. This is mostly just a cleanup, but could in principle be a bugfix if there is some codepath that reaches here and didn't previously require a complete type (I couldn't find any such codepath, though). llvm-svn: 256037
* [Sema] Use UnaryOperatorKind and BinaryOperatorKind in parameter lists ↵Craig Topper2015-12-101-9/+4
| | | | | | instead of just unsigned. Removes a few explicit casts. NFC llvm-svn: 255232
* Add tests for `&enable_if_function` diagnostics.George Burgess IV2015-12-031-1/+0
| | | | | | | | The introduction of pass_object_size fixed a few bugs related to taking the address of a function with enable_if attributes. This patch adds tests for the cases that were fixed. llvm-svn: 254646
* Add the `pass_object_size` attribute to clang.George Burgess IV2015-12-021-40/+152
| | | | | | | | | | | | | `pass_object_size` is our way of enabling `__builtin_object_size` to produce high quality results without requiring inlining to happen everywhere. A link to the design doc for this attribute is available at the Differential review link below. Differential Revision: http://reviews.llvm.org/D13263 llvm-svn: 254554
* [modules] Follow the C++ standard's rule for linkage of enumerators: they haveRichard Smith2015-11-131-10/+43
| | | | | | | | | the linkage of the enumeration. For enumerators of unnamed enumerations, extend the -Wmodules-ambiguous-internal-linkage extension to allow selecting an arbitrary enumerator (but only if they all have the same value, otherwise it's ambiguous). llvm-svn: 253010
* [modules] Generalize the workaround for multiple ambiguous definitions ofRichard Smith2015-11-041-26/+39
| | | | | | | | | | | | | internal linkage entities in different modules from r250884 to apply to all names, not just function names. This is really awkward: we don't want to merge internal-linkage symbols from separate modules, because they might not actually be defining the same entity. But we don't want to reject programs that use such an ambiguous symbol if those internal-linkage symbols are in fact equivalent. For now, we're resolving the ambiguity by picking one of the equivalent definitions as an extension. llvm-svn: 252063
* [MSVC Compat] Permit conversions from pointer-to-function to ↵David Majnemer2015-10-311-1/+9
| | | | | | | | | | | pointer-to-object iff -fms-compatibility We permit implicit conversion from pointer-to-function to pointer-to-object when -fms-extensions is specified. This is rather unfortunate, move this into -fms-compatibility and only permit it within system headers unless -Wno-error=microsoft-cast is specified. llvm-svn: 251738
OpenPOWER on IntegriCloud