Commit Graph

1659 Commits

Author SHA1 Message Date
Benjamin Kramer 6e4f6e1f06 [AST] Turn the callbacks of lookupInBases and forallBases into a function_ref
This lets us pass functors (and lambdas) without void * tricks. On the
downside we can't pass CXXRecordDecl's Find* members (which are now type
safe) to lookupInBases directly, but a lambda trampoline is a small
price to pay. No functionality change intended.

llvm-svn: 243217
2015-07-25 15:07:25 +00:00
Aaron Ballman ddd2ecea9c Silence a -Wtype-limits warning; NFC.
llvm-svn: 242670
2015-07-20 13:36:07 +00:00
Davide Italiano 838838f06a [Sema] Make an assertion stricter.
We now check for the exact range of IdealIndex.

llvm-svn: 242652
2015-07-19 22:07:14 +00:00
Davide Italiano 1a7f648937 [Sema] Refactor Sema::ImplicitExceptionSpecification::CalledDecl
This (hopefully) brings more clarity. No functional changes (intended).

llvm-svn: 242483
2015-07-16 22:37:54 +00:00
Benjamin Kramer 642f173ae9 Switch users of the 'for (StmtRange range = stmt->children(); range; ++range)‘ pattern to range for loops.
The pattern was born out of the lack of range-based for loops in C++98
and is somewhat obscure. No functionality change intended.

llvm-svn: 241300
2015-07-02 21:03:14 +00:00
Richard Smith 9ba0fec83e Rework parsing of pure-specifiers. Perform the grammar matching and
disambiguation in the parser rather than trying to do it in Sema.

llvm-svn: 241032
2015-06-30 01:28:56 +00:00
Alexander Kornienko ab9db51042 Revert r240270 ("Fixed/added namespace ending comments using clang-tidy").
llvm-svn: 240353
2015-06-22 23:07:51 +00:00
Alexander Kornienko 3d9d929e42 Fixed/added namespace ending comments using clang-tidy. NFC
The patch is generated using this command:

  $ tools/extra/clang-tidy/tool/run-clang-tidy.py -fix \
      -checks=-*,llvm-namespace-comment -header-filter='llvm/.*|clang/.*' \
      work/llvm/tools/clang

To reduce churn, not touching namespaces spanning less than 10 lines.

llvm-svn: 240270
2015-06-22 09:47:44 +00:00
David Majnemer 9321f926b0 [MS Compatibility] Handle cleanups we create for a ctor closure
This fixes PR23801.

llvm-svn: 239503
2015-06-11 02:38:06 +00:00
Hans Wennborg fce87cae44 Enable DLL attribute propagation on explicit instantiation definitions (PR23770)
This is a follow-up to r225570 which enabled adding DLL attributes when a
class template goes from explicit instantiation declaration to explicit
instantiation definition.

llvm-svn: 239375
2015-06-09 00:39:09 +00:00
Hans Wennborg bb1983cf3a Enable propagation of dll attributes to previously instantiated base class templates in some cases
It is safe to add a dll attribute if the base class template previously only had
an explicit instantiation declaration, or was implicitly instantiated.

I both those cases, the members would not have been codegenned yet. In the case
of explicit instantiation declaration this is natural, and for implicit
instantiations, codegen is deferred (see r225570).

This is work towards fixing PR23770.

llvm-svn: 239373
2015-06-09 00:39:03 +00:00
Hans Wennborg 29b7a93935 Narrow the -Wunsupported-dll-base-class-template warning.
Don't warn about not being able to propagate dll attribute to a base class template
when that base already has a different attribute.

MSVC doesn't actually try to do this; the first attribute that was propagated
takes precedence, so Clang is already doing the right thing and there's no
need to warn.

(This is a step towards fixing PR21718.)

llvm-svn: 239372
2015-06-09 00:38:56 +00:00
Hans Wennborg 17f9b4469e clang-cl: Handle dll attributes in explicit class template specialization definitions (PR23667)
Previously, we wouldn't call checkDLLAttribute() after the class template
specialization definition if the class template was already instantiated
by an explicit class template specialization declaration.

llvm-svn: 238266
2015-05-27 00:06:45 +00:00
David Majnemer ab6607ab09 [Sema] Don't crash on out-of-line virtual constexpr functions
The method wasn't an overrider but didn't have 'virtual' textually
written because our CXXMethodDecl was an out-of-line definition.  Make
sure we use the canonical decl instead.

This fixes PR23629.

llvm-svn: 237999
2015-05-22 05:49:41 +00:00
Richard Smith c7d48d1a16 [modules] Support merging a parsed default function/template argument with an imported but hidden one.
llvm-svn: 237814
2015-05-20 17:50:35 +00:00
David Majnemer b710a938d6 Give isCompatibleWithMSVC a better interface
We now use an enum which maps the marketing name (almost always a year)
to the major version number.

llvm-svn: 236967
2015-05-11 03:57:49 +00:00
David Majnemer 30f058aa9d [MS ABI] Import move assignment operators
MSVC 2015 changed behavior from 2013; it imports move assignment
operators.

llvm-svn: 236966
2015-05-11 03:00:22 +00:00
Richard Smith 419bd09415 PR23373: A defaulted union copy constructor that is not trivial must still be
emitted as a memcpy.

llvm-svn: 236142
2015-04-29 19:26:57 +00:00
Hans Wennborg 287231cb7a Don't dllimport/export class members with internal linkage (PR23308)
For example, a function taking a parameter with internal linkage will
itself have internal linkage since it cannot be called outside the
translation unit.

Differential Revision: http://reviews.llvm.org/D9182

llvm-svn: 235471
2015-04-22 04:05:17 +00:00
Reid Kleckner 9386417047 Use the most recent previous decl to check if inline is added after a definition
This affects this test case:
  void foo();
  template <typename T> class C {
    friend inline void foo();
  };
  inline void foo() {}
  C<int> c;

Here, we instantiate the foo friend decl and add it to foo's redecl
chain. However, our previous decl pointer happens to reference the first
declaration of foo, which is not marked inline. When we check to see if
foo was already defined, we implicitly search all previous decls. We
should do the same for the inline check, instead of just checking this
particular previous decl.

Reviewers: rsmith

Differential Revision: http://reviews.llvm.org/D8872

llvm-svn: 234374
2015-04-08 00:04:47 +00:00
Richard Smith 78163e2356 Minor simplification: do typo-correction before handling inheriting
constructors, instead of having the typo-correction code also dispatch to the
inheriting constructor special case.

llvm-svn: 233833
2015-04-01 19:31:06 +00:00
Benjamin Kramer fe25759022 [Sema] Implement DR777
A parameter pack after a default argument is now valid.

PR23029.

llvm-svn: 233377
2015-03-27 13:58:41 +00:00
Benjamin Kramer 3b8044c02d [Sema] Diagnose default argument on a parameter pack.
This is ill-formed (and cannot be used anyways).

PR23028.

llvm-svn: 233376
2015-03-27 13:58:31 +00:00
Reid Kleckner 93f661a1da MS ABI: Build C++ default argument exprs for exported template classes
This was an omission from r232229.

llvm-svn: 232554
2015-03-17 21:51:43 +00:00
Reid Kleckner bba3cb95cc MS ABI: Delay default constructor closure checking until the outermost class scope ends
Previously, we would error out on this code because the default argument
wasn't parsed until the end of Outer:

  struct __declspec(dllexport) Outer {
    struct __declspec(dllexport) Inner {
      Inner(void *p = 0);
    };
  };

Now we do the checking on the closing brace of Outer instead of Inner.

llvm-svn: 232519
2015-03-17 19:00:50 +00:00
David Majnemer f9bde287e8 Sema: Properly track mangling number/name for linkage for using decls
Using declarations which are aliases to struct types have their name
used as the struct type's name for linkage purposes.  Otherwise, make
sure to give an anonymous struct defined inside a using declaration a
mangling number to disambiguate it from other anonymous structs in the
same context.

This fixes PR22809.

llvm-svn: 231909
2015-03-11 06:45:39 +00:00
Nico Weber 3b00fdce07 Wrap to 80 columns. No behavior change.
llvm-svn: 231573
2015-03-07 19:52:39 +00:00
David Majnemer fba75df599 Sema: Caught exception objects should be unqualified
The exception object should be unqualified.  Using a qualified exception
object results in the wrong copy constructor getting called when the
catch handler executes.

llvm-svn: 231054
2015-03-03 04:38:34 +00:00
Richard Smith 91c18de755 Rework our handling of key functions. We used to track a complete list of all
dynamic classes in the translation unit and check whether each one's key
function is defined when we got to the end of the TU (and when we got to the
end of each module). This is really terrible for modules performance, since it
causes unnecessary deserialization of every dynamic class in every compilation.

We now use a much simpler (and, in a modules build, vastly more efficient)
system: when we see an out-of-line definition of a virtual function, we check
whether that function was in fact its class's key function. (If so, we need to
emit the vtable.)

llvm-svn: 230830
2015-02-28 01:01:56 +00:00
Richard Smith 7d7dee753d [modules] Properly check whether a declaration is std::initializer_list. This
bug is not actually modules-specific, but it's a little tricky to tickle it
outside of modules builds, so submitting with the reduced testcase I have.

llvm-svn: 230303
2015-02-24 03:30:14 +00:00
Richard Smith cf4bdde33a Cleanup: remove artificial division between lookup results and const lookup
results. No-one was ever modifying a lookup result, and it would not be
reasonable to do so.

llvm-svn: 230123
2015-02-21 02:45:19 +00:00
Hans Wennborg 5870373d19 Improve diagnostic when failing to synthesize implicit member due to dllexport (PR22591)
This is only a problem in C++03 mode targeting MS ABI (MinGW doesn't
export inline methods, and C++11 marks these methods implicitly
deleted).

Since targeting the MS ABI in pre-C++11 mode is a rare configuration,
this will probably not get fixed, but we can at least have a better
error message.

llvm-svn: 230115
2015-02-21 01:07:24 +00:00
Hans Wennborg 97cbed422c Don't dllexport inline methods when targeting MinGW.
MinGW neither imports nor exports such methods. The import bit was
committed earlier, in r221154, and this takes care of the export part.

This also partially fixes PR22591.

llvm-svn: 229922
2015-02-19 22:39:24 +00:00
Nathan Sidwell 5bb231c279 FIX PR 18432, default args, friends & late-parsed members.
Sema::MergeCXXFunctionDecl: propagate hasUnparsedDefaultArg to new decl.

Parser::HandleMemberFunctionDeclDelays: check hasUnparsedDefaultArg
flag.

Parser::ParseLexedMethodDeclaration: handle inherited unparsed default
arg case.

llvm-svn: 229852
2015-02-19 14:03:22 +00:00
Aaron Ballman abc1892057 Removing LLVM_DELETED_FUNCTION, as MSVC 2012 was the last reason for requiring the macro. NFC; Clang edition.
llvm-svn: 229339
2015-02-15 22:54:08 +00:00
Nathan Sidwell 55d53fe79f Code cleanup
Parser::ParseLexedMethodDeclaration: Use local var for Param
Sema::MergeCXXFunctionDecls: Use hasInheritedDefaultArg

llvm-svn: 227577
2015-01-30 14:21:35 +00:00
Nico Weber b3a9978dc8 Don't let virtual calls and dynamic casts call Sema::MarkVTableUsed().
clang currently calls MarkVTableUsed() for classes that get their virtual
methods called or that participate in a dynamic_cast. This is unnecessary,
since CodeGen only emits vtables when it generates constructor, destructor, and
vtt code. (*)

Note that Sema::MarkVTableUsed() doesn't cause the emission of a vtable.
Its main user-visible effect is that it instantiates virtual member functions
of template classes, to make sure that if codegen decides to write a vtable
all the entries in the vtable are defined.

While this shouldn't change the behavior of codegen (other than being faster),
it does make clang more permissive: virtual methods of templates (in particular
destructors) end up being instantiated less often. In particular, classes that
have members that are smart pointers to incomplete types will now get their
implicit virtual destructor instantiated less frequently. For example, this
used to not compile but does now compile:

    template <typename T> struct OwnPtr {
      ~OwnPtr() { static_assert((sizeof(T) > 0), "TypeMustBeComplete"); }
    };
    class ScriptLoader;
    struct Base { virtual ~Base(); };
    struct Sub : public Base {
      virtual void someFun() const {}
      OwnPtr<ScriptLoader> m_loader;
    };
    void f(Sub *s) { s->someFun(); }

The more permissive behavior matches both gcc (where this is not often
observable, since in practice most things with virtual methods have a key
function, and Sema::DefineUsedVTables() skips vtables for classes with key
functions) and cl (which is my motivation for this change) – this fixes
PR20337.  See this issue and the review thread for some discussions about
optimizations.

This is similar to r213109 in spirit. r225761 was a prerequisite for this
change.

Various tests relied on "a->f()" marking a's vtable as used (in the sema
sense), switch these to just construct a on the stack. This forces
instantiation of the implicit constructor, which will mark the vtable as used.

(*) The exception is -fapple-kext mode: In this mode, qualified calls to
virtual functions (`a->Base::f()`) still go through the vtable, and since the
vtable pointer off this doesn't point to Base's vtable, this needs to reference
Base's vtable directly. To keep this working, keep referencing the vtable for
virtual calls in apple kext mode.

llvm-svn: 227073
2015-01-26 06:23:36 +00:00
NAKAMURA Takumi 6a1565c7e5 SemaDeclCXX.cpp: Suppress a warning. [-Wunused-variable]
llvm-svn: 226441
2015-01-19 09:49:59 +00:00
Nathan Sidwell 44b21749b9 PR6037
Warn on inaccessible direct base

llvm-svn: 226423
2015-01-19 01:44:02 +00:00
Nico Weber a089c7cb4b Wrap to 80 columns. No behavior change.
llvm-svn: 226320
2015-01-16 21:09:43 +00:00
Hans Wennborg fd76d91366 Warn about dllexported explicit class template instantiation declarations (PR22035)
Clang would previously become confused and crash here.

It does not make a lot of sense to export these, so warning seems appropriate.

MSVC will export some member functions for this kind of specializations, whereas
MinGW ignores the dllexport-edness. The latter behaviour seems better.

Differential Revision: http://reviews.llvm.org/D6984

llvm-svn: 226208
2015-01-15 21:18:30 +00:00
Nico Weber b6a5d05a8a Remove ASTConsumer::HandleVTable()'s bool parameter.
Sema calls HandleVTable() with a bool parameter which is then threaded through
three layers.  The only effect of this bool is an early return at the last
layer.

Instead, remove this parameter and call HandleVTable() only if the bool is
true.  No intended behavior change.

llvm-svn: 226096
2015-01-15 04:07:35 +00:00
David Majnemer b3c6d52d3a Parse: Don't crash when default argument in typedef consists of sole '='
We'd crash trying to make the SourceRange for the tokens we'd like to
highlight.  Don't assume there is more than one token makes up the
default argument.

llvm-svn: 225774
2015-01-13 07:42:33 +00:00
Nico Weber f1cebf0d17 Fix grammar-o in comment.
llvm-svn: 225324
2015-01-06 23:54:59 +00:00
David Majnemer 380443a2ac Sema: Variable templates cannot be static bitfield members
We correctly forbid variables but not variable templates.  Diagnose this
case instead of crashing.

llvm-svn: 224905
2014-12-28 22:51:45 +00:00
Richard Smith a865a1683a PR21969: Improve diagnostics for a conversion function that has any pieces of a
declared return type (including a trailing-return-type in C++14).

llvm-svn: 224561
2014-12-19 02:07:47 +00:00
David Majnemer 4d2de1b03f Sema: Don't dyn_cast a null pointer in CheckUsingDeclQualifier
This code was written with the intent that a pointer could be null but
we dyn_cast'd it anyway.  Change the dyn_cast to a dyn_cast_or_null.

This fixes PR21933.

llvm-svn: 224411
2014-12-17 02:41:36 +00:00
Richard Smith d52186ff5a DR1684: a constexpr member function need not be a member of a literal class type.
llvm-svn: 224388
2014-12-16 23:12:52 +00:00
Hans Wennborg 45810b4631 Clarify the code in checkDLLAttribute()
Update the comments to make it more clear what's going on, and address
Richard's comments from PR21718. This doesn't fix that bug, but hopefully
makes the code easier to understand.

llvm-svn: 224303
2014-12-16 01:15:01 +00:00
David Majnemer 87ff66ccc7 Parse: MS property members cannot have an in-class initializer
We would crash trying to treat a property member as a field.  These
shoudl be forbidden anyway, reject programs which contain them.

This fixes PR21840.

llvm-svn: 224193
2014-12-13 11:34:16 +00:00