Commit Graph

890 Commits

Author SHA1 Message Date
Douglas Gregor 8a6d0e091b Downgrade the warning about the use of typedefs for class template
specializations within an explicit instantiation to default to off
(enabled by -pedantic). Nobody else seem to implement C++
[temp.explicit]p3. Fixes PR10093.

llvm-svn: 132704
2011-06-07 02:21:18 +00:00
Eli Friedman 9ed3cde1fa Start fixing up clang tests to work on the clang-native-arm-cortex-a9 builder.
llvm-svn: 132691
2011-06-06 21:23:05 +00:00
Douglas Gregor 522d5eb7c3 Diagnose the condition in C++ [temp.expl.spec]p16 that prohibits
specializing a member of an unspecialized template, and recover from
such errors without crashing. Fixes PR10024 / <rdar://problem/9509761>.

llvm-svn: 132677
2011-06-06 15:22:55 +00:00
Douglas Gregor 2f157c9ae2 When checking the instantiation of a default template argument against
the template parameter, perform the checking as a "specified" template
argument rather than a "deduced" template argument; the latter implies
stricter type checking that is not permitted for default template
arguments.

Also, cleanup our handling of substitution of explicit template
arguments for a function template. We were actually performing some
substitution of default arguments at this point!

Fixes PR10069.

llvm-svn: 132529
2011-06-03 02:59:40 +00:00
Douglas Gregor b32e825ae4 Fix an incorrect warning about explicit template specializations for
nested types, from Michael Han!

llvm-svn: 132431
2011-06-01 22:37:07 +00:00
Douglas Gregor 981e37d727 The expression in a noexcept exception-specification is a
constant-expression, and, therefore, an unevaluated operand. Make it
so.

llvm-svn: 132400
2011-06-01 15:55:51 +00:00
John McCall 9b382dde92 Convert Clang over to resuming from landing pads with llvm.eh.resume.
It's quite likely that this will explode, but I need to know how. :)

llvm-svn: 132269
2011-05-28 21:13:02 +00:00
Eli Friedman 380b8dad6b Back out r132209; it's breaking nightly tests.
llvm-svn: 132219
2011-05-27 21:32:17 +00:00
Douglas Gregor 22ae696be7 Clean up my changes to jump-diagnostic handling for local variables of
class type (or array thereof), eliminating some redundant checks
(thanks Eli!) and adding some tests where the behavior differs in
C++98/03 vs. C++0x.

llvm-svn: 132218
2011-05-27 21:28:00 +00:00
John McCall 63fb333fa4 Implement a new, much improved version of the cleanup hack. We just need
to be careful to emit landing pads that are always prepared to handle a
cleanup path.  This is correct mostly because of the fix to the LLVM
inliner, r132200.

llvm-svn: 132209
2011-05-27 20:01:14 +00:00
Douglas Gregor 27d0c44524 Update the jump-scope checker for local variables with initializers,
so that it looks at the initializer of a local variable of class type
(or array thereof) to determine whether it's just an implicit
invocation of the trivial default constructor. Fixes PR10034.

llvm-svn: 132191
2011-05-27 16:05:29 +00:00
Alexis Hunt 119c10ef23 Update our diagnostics to properly account for move operations.
llvm-svn: 132096
2011-05-25 23:16:36 +00:00
Douglas Gregor fcafc6e3de Implement the initial part of C++0x [expr.const]p2, which specifies
that the unevaluated subexpressions of &&, ||, and ? : are not
considered when determining whether the expression is a constant
expression. Also, turn the "used in its own initializer" warning into
a runtime-behavior warning, so that it doesn't fire when a variable is
used as part of an unevaluated subexpression of its own initializer.

Fixes PR9999.

llvm-svn: 131968
2011-05-24 16:02:01 +00:00
Douglas Gregor 291e8ee206 It's considered poor form to create references to the overloaded
function type. Educate template argument deduction thusly, fixing
PR9974 / <rdar://problem/9479155>.

llvm-svn: 131811
2011-05-21 22:16:50 +00:00
Douglas Gregor 781ba6e407 Diagnose the presence of storage-class-specifiers on explicit
instantiations and specializations. Fixes <rdar://problem/9126453> and PR8700.

llvm-svn: 131802
2011-05-21 18:53:30 +00:00
Douglas Gregor 9574af6ea2 Teach Sema::ActOnUninitializedDecl() not to try to interpret when one
should use a constructor to default-initialize a
variable. InitializationSequence knows the rules for default
initialization, better. Fixes <rdar://problem/8501008>.

llvm-svn: 131796
2011-05-21 17:52:48 +00:00
Douglas Gregor 253cadfe68 Implement C++0x semantics for passing non-POD classes through varargs.
llvm-svn: 131792
2011-05-21 16:27:21 +00:00
Douglas Gregor a912197fff Downgrade the error about re-opening an inline namespace as non-inline
to a warning, since apparently libstdc++'s debug mode does this (and
we can recover safely). Add a Fix-It to insert the "inline", just for kicks.

llvm-svn: 131732
2011-05-20 15:48:31 +00:00
Douglas Gregor 4385d8b0a2 Diagnose unexpanded parameter packs in return statements. This
manifested in a crash with blocks in PR9953, but it was a ticking time
bomb for normal functions, too. Fixes PR9953.

llvm-svn: 131731
2011-05-20 15:32:55 +00:00
Sebastian Redl 645d958035 Fix PR9941 for out-of-line template destructors too.
llvm-svn: 131722
2011-05-20 05:57:18 +00:00
Matt Beaumont-Gay 6c307aee7b Undo enough of r131143 to make private copy ctor diags say "copy constructor" again
llvm-svn: 131706
2011-05-19 23:44:42 +00:00
Sebastian Redl 8035d1c435 Fix PR9941 again, this time for templates.
llvm-svn: 131640
2011-05-19 16:25:27 +00:00
Sebastian Redl 623ea82a6b Reapply r121528, fixing PR9941 by delaying the exception specification check for destructors until the class is complete and destructors have been adjusted.
llvm-svn: 131632
2011-05-19 05:13:44 +00:00
Alexis Hunt d0cdd1fab1 Revert r121528 as it breaks a simple testcase, which leads to, among
other things, libcxx not building.

llvm-svn: 131573
2011-05-18 20:57:11 +00:00
Sebastian Redl b900f04ccc Implement implicit exception specifications of destructors.
llvm-svn: 131528
2011-05-18 05:20:56 +00:00
Douglas Gregor 9d07dfa439 When checking a set of template parameter lists against a
nested-name-specifier, re-evaluate the nested-name-specifier as if we
were entering that context (which we did!), so that we'll resolve a
template-id to a particular class template partial
specialization. Fixes PR9913.

llvm-svn: 131383
2011-05-15 17:27:27 +00:00
Richard Smith 0c4a34b1a0 PR9908: Fix the broken fix for PR9902 to get the template argument lists in the right order.
Also, don't reject alias templates in all ElaboratedTypes: some ElaboratedTypes do not correspond to elaborated-type-specifiers.

llvm-svn: 131342
2011-05-14 15:04:18 +00:00
Eli Friedman 622e4fcac6 PR9899: handle pseudo-destructors correctly in noexcept() expressions.
llvm-svn: 131220
2011-05-12 02:11:32 +00:00
Douglas Gregor 347d626cf7 Implement CWG1170, which makes access-control errors into template
argument deduction failures. Only implemented in C++0x, since this is
a significant change in behavior from C++98/03.

llvm-svn: 131209
2011-05-11 23:45:11 +00:00
Douglas Gregor 373af9bc5d When checking for the necessary 'template<>' headers based on the
nested of an out-of-line declaration, only require a 'template<>'
header for each enclosing class template that hasn't been previously
specialized; previously, we were requiring 'template<>' for enclosing
class templates and members of class templates that hadn't been
previously specialized. Fixes <rdar://problem/9422013>.

llvm-svn: 131207
2011-05-11 23:26:17 +00:00
Eli Friedman c6587cc550 PR9882: Fix noexcept to deal with dependent new, delete, calls, and
dynamic_cast correctly.

llvm-svn: 131177
2011-05-11 05:22:44 +00:00
Douglas Gregor 932aac6492 Tweak the diagnostics for the C++0x extensions to friend types to note
that they are C++0x extensions, and put them in the appropriate
group. We already support most of the semantics. Addresses
<rdar://problem/9407525>.

llvm-svn: 131153
2011-05-10 21:23:31 +00:00
Alexis Hunt 80f00ff95d Re-do R131114 without breaking code.
I've edited one diagnostic which would print "copy constructor" for copy
constructors and "constructor" for any other constructor. If anyone is
extremely enamored with this, it can be reinstated with a simple boolean
flag rather than calling getSpecialMember, which is inappropriate.

llvm-svn: 131143
2011-05-10 19:08:14 +00:00
Douglas Gregor 972fe534ed Reimplement Sema::MatchTemplateParametersToScopeSpecifier() based on
the semantic context referenced by the nested-name-specifier rather
than the syntactic form of the nested-name-specifier. The previous
incarnation was based on my complete misunderstanding of C++
[temp.expl.spec]. The latest C++0x working draft clarifies the
requirements here, and this rewrite is intended to follow that.

Along the way, improve source location information in the
diagnostics. For example, if we report that a specific type needs or
doesn't need a 'template<>' header, we dig out that type in the
nested-name-specifier and highlight its range.

Fixes: PR5907, PR9421, PR8277, PR8708, PR9482, PR9668, PR9877, and
<rdar://problem/9135379>.

llvm-svn: 131138
2011-05-10 18:27:06 +00:00
Richard Smith 14034026d6 Slight tweak to alias template error handling: don't guess that a template-id in an alias declaration was meant to be a specialization. Use a generic, but more accurate, diagnostic.
llvm-svn: 130961
2011-05-05 22:36:10 +00:00
Richard Smith 3f1b5d077b Implement support for C++0x alias templates.
llvm-svn: 130953
2011-05-05 21:57:07 +00:00
Richard Trieu ae700c971c Fix a typo in a test.
CHEKC -> CHECK

llvm-svn: 130809
2011-05-04 00:16:24 +00:00
Chandler Carruth 7c9856deb3 When parsing a template friend declaration we dropped the template
parameters on the floor in certain cases:
class X {
  template <typename T> friend typename A<T>::Foo;
};

This was parsed as a *non* template friend declaration some how, and
received an ExtWarn. Fixing the parser to actually provide the template
parameters to the freestanding declaration parse triggers the code which
specifically looks for such constructs and hard errors on them.

Along the way, this prevents us from trying to instantiate constructs
like the above inside of a outer template. This is important as loosing
the template parameters means we don't have a well formed declaration
and template instantiation will be unable to rebuild the AST. That fixes
a crash in the GCC test suite.

llvm-svn: 130772
2011-05-03 18:35:10 +00:00
John McCall 5476666d17 Diagnose attempts to implicitly instantiate a template before it is
fully defined.  Somehow this escaped notice for a very long time.

llvm-svn: 130298
2011-04-27 06:46:31 +00:00
Douglas Gregor 8b02cd0bea Extend Sema::ClassifyName() to support C++, ironing out a few issues
in the classification of template names and using declarations. We now
properly typo-correct the leading identifiers in statements to types,
templates, values, etc. As an added bonus, this reduces the number of
lookups required for disambiguation.

llvm-svn: 130288
2011-04-27 04:48:22 +00:00
John McCall 0009fcc39e Make yet another placeholder type, this one marking that an expression is a bound
member function, i.e. something of the form 'x.f' where 'f' is a non-static
member function.  Diagnose this in the general case.  Some of the new diagnostics
are probably worse than the old ones, but we now get this right much more
universally, and there's certainly room for improvement in the diagnostics.

llvm-svn: 130239
2011-04-26 20:42:42 +00:00
Richard Smith dda56e4b4a Support for C++11 (non-template) alias declarations.
llvm-svn: 129567
2011-04-15 14:24:37 +00:00
Chris Lattner 57540c5be0 fix a bunch of comment typos found by codespell. Patch by
Luis Felipe Strano Moraes!

llvm-svn: 129559
2011-04-15 05:22:18 +00:00
Richard Smith 02e85f3bc5 Add support for C++0x's range-based for loops, as specified by the C++11 draft standard (N3291).
llvm-svn: 129541
2011-04-14 22:09:26 +00:00
Richard Smith f7b6202e6c Implement C++0x [lex.pptoken]p3's handling of <::.
llvm-svn: 129525
2011-04-14 18:36:27 +00:00
Argyrios Kyrtzidis 36e4ae3e57 When creating an implicit member expression through a qualified-id, check that the class
named by the nested-name-specifier is same or base of the class in which the member expression appears.

It seems we also had an ill-formed test case, mon dieu! Fixes rdar://8576107.

llvm-svn: 129493
2011-04-14 00:46:47 +00:00
John McCall a97f329869 Template static data members can have weak_odr linkage, not just
weak linkage.  Also, fix a problem where global weak variables
with non-trivial initializers were getting guard variables, or at
least were checking for them and then crashing.

llvm-svn: 129342
2011-04-12 01:46:54 +00:00
John McCall 9fcede85dd This test works now; enable it.
llvm-svn: 129335
2011-04-12 00:57:12 +00:00
Eli Friedman 554eba9c08 PR9669: implement correct checking for [dcl.init.string]p2.
llvm-svn: 129260
2011-04-11 00:23:45 +00:00
John McCall 3aef3d8713 Simplify calling CheckPlaceholderExpr, converge on it in a few places,
and move a vector-splat check to follow l-value conversion.

llvm-svn: 129254
2011-04-10 19:13:55 +00:00
Ted Kremenek 99a337eed0 When emitting a "too many arguments to function call..." error, also include a note with a location for the function prototype.
llvm-svn: 128833
2011-04-04 17:22:27 +00:00
Chandler Carruth ffce245700 Fix a bug in how we were resolving the address of overloaded functions
when the resolution took place due to a single template specialization
being named with an explicit template argument list. In this case, the
"resolution" doesn't take into account the target type at all, and
therefore can take place for functions, static member functions, and
*non-static* member functions. The latter weren't being properly checked
and their proper form enforced in this scenario. We now do so.

The result of this last form slipping through was some confusing logic
in IsStandardConversion handling of these resolved address-of
expressions which eventually exploded in an assert. Simplify this logic
a bit and add some more aggressive asserts to catch improperly formed
expressions getting into this routine.

Finally add systematic testing of member functions, both static and
non-static, in the various forms they can take. One of these is
essentially PR9563, and this commit fixes the crash in that PR. However,
the diagnostics for this are still pretty terrible. We at least are now
accepting the correct constructs and rejecting the invalid ones rather
than accepting invalid or crashing as before.

llvm-svn: 128456
2011-03-29 08:08:18 +00:00
Anders Carlsson f9eb63beb7 Replace the call to ParseOptionalCXX0XClassVirtSpecifierSeq with code to only parse an optional 'final' keyword.
llvm-svn: 128278
2011-03-25 14:46:08 +00:00
Anders Carlsson 30f29444c0 Get rid of handling of the 'explicit' keyword from class-head. We still parse it though, although that will change shortly.
llvm-svn: 128277
2011-03-25 14:31:08 +00:00
Anders Carlsson 806aa66e8f Remove warnings about using override control keywords in inline function definitions; they will be allowed in the next C++0x draft.
llvm-svn: 128273
2011-03-25 11:28:25 +00:00
Anders Carlsson debd3ec14d Remove 'new' from virt-specifier since it's going to be removed in the next C++0x draft
llvm-svn: 128271
2011-03-25 11:19:41 +00:00
Douglas Gregor 63fab34469 Detect attempts to provide a specialization of a function within a
dependent scope and produce an error (rather than crashing). Fixes PR8979.

llvm-svn: 127749
2011-03-16 19:27:09 +00:00
Douglas Gregor 89f3cd5c15 Clean up our handling of template-ids that resolve down to a single
overload, so that we actually do the resolution for full expressions
and emit more consistent, useful diagnostics. Also fixes an IRGen
crasher, where Sema wouldn't diagnose a resolvable bound member
function template-id used in a full-expression (<rdar://problem/9108698>).

llvm-svn: 127747
2011-03-16 19:16:25 +00:00
Sebastian Redl e800838170 Fix test case.
llvm-svn: 127699
2011-03-15 21:15:06 +00:00
Sebastian Redl 52ddca23a7 Extend the noexcept expression test to test noexcept specification functions.
llvm-svn: 127693
2011-03-15 20:45:42 +00:00
Sebastian Redl c34c29f661 More robust check for the special C++0x operator new workaround.
llvm-svn: 127692
2011-03-15 20:41:09 +00:00
Sebastian Redl cb5dd00796 Implement a hack to work around the changing exception specification of operator new in C++0x.
llvm-svn: 127688
2011-03-15 19:52:30 +00:00
Sebastian Redl 0b94c9fb69 Reintroduce r127617: "Code generation for noexcept." with fixes.
llvm-svn: 127685
2011-03-15 18:42:48 +00:00
Jakob Stoklund Olesen fcaa2e1ba4 Revert r127617: "Code generation for noexcept."
The tests fail in a -Asserts build.

llvm-svn: 127635
2011-03-15 00:18:21 +00:00
Sebastian Redl 97022fd325 Code generation for noexcept.
llvm-svn: 127617
2011-03-14 20:33:20 +00:00
Sebastian Redl 771f57de1c Implement instantiation of noexcept spec and add a test case.
llvm-svn: 127603
2011-03-14 18:51:50 +00:00
Sebastian Redl 849385bf76 Add another, pretty trivial, exception spec test case.
llvm-svn: 127602
2011-03-14 18:51:44 +00:00
Sebastian Redl 37588097af Make deallocation functions implicitly noexcept in C++0x.
llvm-svn: 127596
2011-03-14 18:08:30 +00:00
Sebastian Redl c1f8e493da Revert "Disable inherited constructors for 2.9."
It is only meant for the release branch.

llvm-svn: 127542
2011-03-12 13:44:32 +00:00
Sebastian Redl 1dc2c1d27f Disable inherited constructors for 2.9.
llvm-svn: 127541
2011-03-12 13:44:23 +00:00
Sebastian Redl fa453cfdc3 Propagate the new exception information to FunctionProtoType.
Change the interface to expose the new information and deal with the enormous fallout.
Introduce the new ExceptionSpecificationType value EST_DynamicNone to more easily deal with empty throw specifications.
Update the tests for noexcept and fix the various bugs uncovered, such as lack of tentative parsing support.

llvm-svn: 127537
2011-03-12 11:50:43 +00:00
Daniel Dunbar 334b2136f6 Revert r127206 "Detect attempts to provide a specialization of a function within
a...", it appears to cause us to reject various valid codes.

llvm-svn: 127373
2011-03-09 23:24:34 +00:00
Douglas Gregor 6203d49b0e Detect attempts to provide a specialization of a function within a
dependent scope and produce an error (rather than crashing). Fixes PR8979.

llvm-svn: 127206
2011-03-08 02:04:14 +00:00
Douglas Gregor db44611f2e Support explicit template specialization and instantiation for members
of a C++0x inline namespace within enclosing namespaces, as noted in
C++0x [namespace.def]p8.

Fixes <rdar://problem/9006349>, a libc++ failure where Clang was
rejected an explicit specialization of std::swap (since libc++ puts it
into an inline, versioned namespace std::__1).

llvm-svn: 127162
2011-03-07 16:54:27 +00:00
Douglas Gregor 0ec210bc88 Produce a diagnostic for unused overloaded expressions, from Faisal Vali!
llvm-svn: 127148
2011-03-07 02:05:23 +00:00
Sebastian Redl 965b0e3106 Parser support for noexcept specifications.
llvm-svn: 127086
2011-03-05 14:45:16 +00:00
John McCall 8feeb49662 Semantic checking for exception specifications should be triggered by
whether C++ exceptions are enabled, not exceptions in general.  PR9358.

llvm-svn: 126820
2011-03-02 02:04:40 +00:00
Douglas Gregor c52264e719 When we're substituting into a parameter-type-list nested inside the pattern
of an expansion, and we have a paramameter that is not a parameter
pack, don't suppress substitution of parameter packs within this
context.

llvm-svn: 126819
2011-03-02 02:04:06 +00:00
Anders Carlsson 6774b1f1c1 Add -fcxx-exceptions to all tests that use C++ exceptions.
llvm-svn: 126599
2011-02-28 00:40:07 +00:00
Fariborz Jahanian bb6db56028 Provide Fixit warning when 'auto' is intended as storage
specifier in legacy code. Patch is reviewed offline by Doug.
// rdar://9036633.

llvm-svn: 126261
2011-02-22 23:17:49 +00:00
Richard Smith 59006e4338 Fix a few auto-related issues:
* 'auto' was being rejected on abstract-declarators with trailing return
types and on typedefs with trailing return types. 'auto' is always
allowed in these cases. This was found while testing the fix for PR 9278.

 * A very poor diagnostic was being issued for auto (f() -> int): "return
type must be 'auto', not 'auto'". This is closely related to PR 9060.

 * Trailing return type handling was happening slightly too late,
resulting in the checks for functions returning arrays and functions
returning functions being missed.

llvm-svn: 126166
2011-02-22 00:36:53 +00:00
Richard Smith e51cb7dedf Add reference to PR 9278 for archaeologists.
llvm-svn: 126164
2011-02-22 00:19:36 +00:00
Richard Smith 27e39b11b1 C++0x's deduced auto is illegal in typedefs.
This actually rules out too much, since it also catches typedefs for pointers to functions with trailing return types:

  typedef auto (*F)() -> int;

Fix for that (and the same issue in all abstract-declarators) to follow shortly.

llvm-svn: 126153
2011-02-21 23:18:00 +00:00
Richard Smith b2bc2e6752 Tweaks to C++0x deduced auto type support:
* Flag indicating 'we're parsing this auto typed variable's initializer' moved from VarDecl to Sema
 * Temporary template parameter list for auto deduction is now allocated on the stack.
 * Deduced 'auto' types are now uniqued.

llvm-svn: 126139
2011-02-21 20:05:19 +00:00
Richard Smith 30482bc786 Implement the C++0x deduced 'auto' feature.
This fixes PR 8738, 9060 and 9132.

llvm-svn: 126069
2011-02-20 03:19:35 +00:00
Douglas Gregor b491ed36b4 Handle the resolution of a reference to a function template (which
includes explicitly-specified template arguments) to a function
template specialization in cases where no deduction is performed or
deduction fails. Patch by Faisal Vali, fixes PR7505!

llvm-svn: 126048
2011-02-19 21:32:49 +00:00
Anders Carlsson 479d6f51e3 Pass -fexceptions to all tests that use try/catch/throw.
llvm-svn: 126037
2011-02-19 19:23:03 +00:00
Chandler Carruth 98e3c568bf Fix PR8767, improve diagnostic wording when allocating an object of an
abstract class type.

Patch by Stephen Hines, with a wording tweak from Doug applied by me.

llvm-svn: 125996
2011-02-18 23:59:51 +00:00
Douglas Gregor b327eac117 Implement C++0x [expr.static.cast]p9, which permits explicitly casting
a scoped enumeration type to an integral or floating type,
properly. There was an over-eager assertion, and it was missing the
floating-point case.

Fixes PR9107/<rdar://problem/8937402>. 

llvm-svn: 125825
2011-02-18 03:01:41 +00:00
Chris Lattner c8e630e4db Step #1/N of implementing support for __label__: split labels into
LabelDecl and LabelStmt.  There is a 1-1 correspondence between the
two, but this simplifies a bunch of code by itself.  This is because
labels are the only place where we previously had references to random
other statements, causing grief for AST serialization and other stuff.

This does cause one regression (attr(unused) doesn't silence unused
label warnings) which I'll address next.

This does fix some minor bugs:
1. "The only valid attribute " diagnostic was capitalized.
2. Various diagnostics printed as ''labelname'' instead of 'labelname'
3. This reduces duplication of label checking between functions and blocks.

Review appreciated, particularly for the cindex and template bits.

llvm-svn: 125733
2011-02-17 07:39:24 +00:00
Douglas Gregor b0f2ea9e9e When printing a qualified type, look through a substituted template
parameter type to see what's behind it, so that we don't end up
printing silly things like "float const *" when "const float *" would
make more sense. Also, replace the pile of "isa" tests with a simple
switch enumerating all of the cases, making a few more obvious cases
use prefix qualifiers.

llvm-svn: 125729
2011-02-17 06:52:25 +00:00
John McCall 9743e8d84e Handle delayed access in local declarations. PR9229.
llvm-svn: 125609
2011-02-15 22:51:53 +00:00
John McCall 25849cab8b Return a declaration to the parser when creating a field in C++ so that
the parser will complete the declarator with a valid decl and thus trigger
delayed diagnostics for it.  It certainly looks like we were intentionally
returning null here, but I couldn't find any good reason for it, and there
wasn't a comment, so farewell to all that.

llvm-svn: 125556
2011-02-15 07:12:36 +00:00
John McCall fe9cf0abb7 Don't crash on hierarchy static_casts which appear in variable initializers.
PR9221.

llvm-svn: 125532
2011-02-14 23:21:33 +00:00
John McCall 2957e3ef49 Change the context correctly when instantiating a static data member definition.
llvm-svn: 125517
2011-02-14 20:37:25 +00:00
John McCall 909acf8209 Provide overload diagnostics when explicit casts involving class types fail.
PR8626.

llvm-svn: 125506
2011-02-14 18:34:10 +00:00
John McCall c146582e60 When parsing an out-of-line member function declaration, we must delay
access-control diagnostics which arise from the portion of the declarator
following the scope specifier, just in case access is granted by
friending the individual method.  This can also happen with in-line
member function declarations of class templates due to templated-scope
friend declarations.

We were really playing fast-and-loose before with this sort of thing,
and it turned out to work because *most* friend functions are in file
scope.  Making us delay regardless of context exposed several bugs with
how we were manipulating delay.  I ended up needing a concept of a
context that's independent of the declarations in which it appears,
and then I actually had to make some things save contexts correctly,
but delay should be much cleaner now.

I also encapsulated all the delayed-diagnostics machinery in a single
subobject of Sema;  this is a pattern we might want to consider rolling
out to other components of Sema.

llvm-svn: 125485
2011-02-14 07:13:47 +00:00
John McCall 351762cda2 A few more tweaks to the blocks AST representation:
- BlockDeclRefExprs always store VarDecls
  - BDREs no longer store copy expressions
  - BlockDecls now store a list of captured variables, information about
    how they're captured, and a copy expression if necessary
    
With that in hand, change IR generation to use the captures data in       
blocks instead of walking the block independently.        

Additionally, optimize block layout by emitting fields in descending
alignment order, with a heuristic for filling in words when alignment
of the end of the block header is insufficient for the most aligned
field.

llvm-svn: 125005
2011-02-07 10:33:21 +00:00
Sebastian Redl 0890502f44 Basic implementation of inherited constructors. Only generates declarations, and probably only works for very basic use cases.
llvm-svn: 124970
2011-02-05 19:23:19 +00:00
Douglas Gregor 125fa40c34 When calling a bound pointer to member function, check the
cv-qualifiers on the object against the cv-qualifiers on the member
function. Fixes PR8315.

llvm-svn: 124865
2011-02-04 12:57:49 +00:00
Douglas Gregor 4d5c297607 Tweak my fix for PR8748, and update the incorrect PR number in the test case.
llvm-svn: 124863
2011-02-04 12:22:53 +00:00
Douglas Gregor a99fb4c77d Tighten up the semantics of default template arguments, per C++0x
[temp.param]p9 and C++ DR226. Fixes PR8747.

llvm-svn: 124856
2011-02-04 04:20:44 +00:00
Douglas Gregor 8b481d8ac2 When a function template's template parameter has a default argument,
it's okay for the following template parameters to not have default
arguments (since those template parameters can still be
deduced). Also, downgrade the error about default template arguments
in function templates to an extension warning, since this is a
harmless C++0x extension.

llvm-svn: 124855
2011-02-04 03:57:22 +00:00
Douglas Gregor fa7781384e Implement access checking for the "delete" operator. Fixes PR9050,
from Alex Miller!

llvm-svn: 124663
2011-02-01 15:50:11 +00:00
Nico Weber 24b2a822dd PR9037: Allow override, final, and new as an extension on inline members.
llvm-svn: 124477
2011-01-28 06:07:34 +00:00
Douglas Gregor 0693defea9 When we run into a template parameter that should have a default
argument but doesn't (because previous template parameters had default
arguments), clear out all of the default arguments so that we maintain
the invariant that a template parameter has a default argument only if
subsequence template parameters also have default arguments.
Fixes a crash-on-invalid <rdar://problem/8913649>.

llvm-svn: 124345
2011-01-27 01:40:17 +00:00
Douglas Gregor dff0be70ba Cope with parenthesized function declarators when emitting a
diagnostic about ref-qualifiers where they do not belong.

llvm-svn: 124344
2011-01-27 01:30:16 +00:00
Douglas Gregor 582813596a Fix a horrible bug in our handling of C-style casting, where a C-style
derived-to-base cast that also casts away constness (one of the cases
for static_cast followed by const_cast) would be treated as a bit-cast
rather than a derived-to-base class, causing miscompiles and
heartburn.

Fixes <rdar://problem/8913298>.

llvm-svn: 124340
2011-01-27 00:58:17 +00:00
Douglas Gregor c83f9865a0 Implement the restriction that a function with a ref-qualifier cannot
overload a function without a ref-qualifier (C++0x
[over.load]p2). This, apparently, completes the implementation of
rvalue references for *this.

llvm-svn: 124321
2011-01-26 21:20:37 +00:00
Douglas Gregor ce95084d5c Handle C-style casts to rvalue reference types that cast away constness.
llvm-svn: 124319
2011-01-26 21:04:06 +00:00
Douglas Gregor e1a47c1766 Rvalue references for *this: explicitly keep track of whether a
reference binding is for the implicit object parameter of a member
function with a ref-qualifier. My previous comment, that we didn't
need to track this explicitly, was wrong: we do in fact get
rvalue-references-prefer-rvalues overloading with ref-qualifiers.

llvm-svn: 124313
2011-01-26 19:41:18 +00:00
Douglas Gregor 0282432039 Rvalue references for *this: implement the implicit conversion rules
for the implicit object argument to a non-static member function with
a ref-qualifier (C++0x [over.match.funcs]p4).

llvm-svn: 124311
2011-01-26 19:30:28 +00:00
Douglas Gregor b2f8aa9556 Rvalue references for *this: allow functions to be overloaded based on
the presence and form of a ref-qualifier. Note that we do *not* yet
implement the restriction in C++0x [over.load]p2 that requires either
all non-static functions with a given parameter-type-list to have a
ref-qualifier or none of them to have a ref-qualifier.

llvm-svn: 124297
2011-01-26 17:47:49 +00:00
Douglas Gregor 54e462ac6e Rvalue references for *this: tentative parsing and template argument deduction.
llvm-svn: 124295
2011-01-26 16:50:54 +00:00
Douglas Gregor 1d042091d3 Reference qualifiers for *this: implement C++0x [expr.mptr.oper]p6,
the restrictions on .* and ->* for ref-qualified pointer-to-member
functions.

llvm-svn: 124294
2011-01-26 16:40:18 +00:00
Douglas Gregor e696ebbd70 Reinstate r124236 (tweaking the rvalue-reference overload resolution
rules), now that we've actually have a clean build for me to sully.

llvm-svn: 124290
2011-01-26 14:52:12 +00:00
Douglas Gregor db9d664244 Rvalue references for *this:
- Add ref-qualifiers to the type system; they are part of the
  canonical type. Print & profile ref-qualifiers
  - Translate the ref-qualifier from the Declarator chunk for
    functions to the function type. 
  - Diagnose mis-uses of ref-qualifiers w.r.t. static member
  functions, free functions, constructors, destructors, etc.
  - Add serialization and deserialization of ref-qualifiers.

llvm-svn: 124281
2011-01-26 05:01:58 +00:00
Douglas Gregor 5499235d13 Rvalue references for *this: parse ref-qualifiers.
llvm-svn: 124276
2011-01-26 03:43:54 +00:00
Douglas Gregor 41e4e2c798 Speculatively revert r124236
llvm-svn: 124247
2011-01-25 23:49:36 +00:00
Douglas Gregor 407371a1e4 Speculatively implement a tweak to the C++0x overload resolution rules
for reference binding (C++ [over.rank.ics]p3b1sb4), so that we prefer
the binding of an lvalue reference to a function lvalue over the
binding of an rvalue reference. This change resolves the ambiguity
with std::forward and lvalue references to function types in a way
that seems consistent with the original rvalue references proposal.

My proposed wording for this change is shown in
isBetterReferenceBindingKind(); we'll try to get this change adopted
in the C++0x working paper as well.

llvm-svn: 124236
2011-01-25 22:19:32 +00:00
Douglas Gregor 1c5a53e200 Fix the ranking of reference bindings during overload resolution
(C++0x [over.ics.rank]p3) when one binding is an lvalue reference and
the other is an rvalue reference that binds to an rvalue. In
particular, we were using the predict "is an rvalue reference" rather
than "is an rvalue reference that binds to an rvalue", which was
incorrect in the one case where an rvalue reference can bind to an
lvalue: function references.

This particular issue cropped up with std::forward, where Clang was
picking an std::forward overload while forwarding an (lvalue)
reference to a function. However (and unfortunately!), the right
answer for this code is that the call to std::forward is
ambiguous. Clang now gets that right, but we need to revisit the
std::forward implementation in libc++.

llvm-svn: 124216
2011-01-25 19:39:31 +00:00
Rafael Espindola 05842dabb8 Move unnamed_addr after the function arguments on Sabre's request.
llvm-svn: 124210
2011-01-25 19:10:24 +00:00
Douglas Gregor 85f240c788 Implement the rvalue-reference deduction transformation (from T&& ->
T) when taking the address of an overloaded function or matching a
specialization to a template (C++0x [temp.deduct.type]p10). Fixes
PR9044.

llvm-svn: 124197
2011-01-25 17:19:08 +00:00
Douglas Gregor f143cd5051 Re-instate r123977/r123978, my updates of the reference-binding
implementation used by overload resolution to support rvalue
references. The original commits caused PR9026 and some
hard-to-reproduce self-host breakage.

The only (crucial!) difference between this commit and the previous
commits is that we now properly check the SuppressUserConversions flag
before attempting to perform a second user-defined conversion in
reference binding, breaking the infinite recursion chain of
user-defined conversions.

Rvalue references should be working a bit better now.

llvm-svn: 124121
2011-01-24 16:14:37 +00:00
Anders Carlsson e30621b626 Get rid of [[hiding]], [[override]] and [[base_check]].
llvm-svn: 124087
2011-01-23 21:33:18 +00:00
Anders Carlsson 19588aa40b Get rid of the [[final]] C++0x attribute.
llvm-svn: 124083
2011-01-23 21:07:30 +00:00
Anders Carlsson 7d59a68330 Implement [class.derived]p8.
llvm-svn: 124047
2011-01-22 22:23:37 +00:00
Anders Carlsson c4964a40ba Mark classes final and/or explicit during class template instantiation.
llvm-svn: 124040
2011-01-22 18:07:06 +00:00
Anders Carlsson fc1eef4898 Mark classes as final or explicit. Diagnose when a class marked 'final' is used as a base.
llvm-svn: 124039
2011-01-22 17:51:53 +00:00
Anders Carlsson 4b63d0e0a7 Parse class-virt-specifier-seqs.
llvm-svn: 124036
2011-01-22 16:56:46 +00:00
Rafael Espindola be468d9a2b revert r123977 and r123978 to fix PR9026.
llvm-svn: 124033
2011-01-22 15:32:35 +00:00
Anders Carlsson e973899f46 A member function template cannot be virtual.
llvm-svn: 124031
2011-01-22 14:43:56 +00:00
Douglas Gregor c1ed20cfba Update const_cast semantics for rvalue references. Add tests for
reinterpret_cast and const_cast using rvalue references.

llvm-svn: 124007
2011-01-22 00:19:52 +00:00
Douglas Gregor 465184ae10 Teach static_cast and dynamic_cast about rvalue references.
llvm-svn: 124006
2011-01-22 00:06:57 +00:00
Douglas Gregor c74edc272e When throwing an elidable object, first try to treat the subexpression
as an rvalue per C++0x [class.copy]p33. If that fails, try again with
the original subexpression.

llvm-svn: 124002
2011-01-21 22:46:35 +00:00
Douglas Gregor f282a76fab Implement the preference for move-construction over copy-construction
when returning an NRVO candidate expression. For example, this
properly picks the move constructor when dealing with code such as

  MoveOnlyType f() { MoveOnlyType mot; return mot; }

The previously-XFAIL'd rvalue-references test case now works, and has
been moved into the appropriate paragraph-specific test case.

llvm-svn: 123992
2011-01-21 19:38:21 +00:00
Douglas Gregor 6381402fe1 Implement core issue 1164, which concerns the partial ordering of
f(T&) and f(T&&).

llvm-svn: 123981
2011-01-21 17:29:42 +00:00
Douglas Gregor cc73795cd8 Add test for overload resolution's preference for binding an rvalue
reference to an rvalue rather than binding a const-qualified lvalue
reference to that rvalue.

llvm-svn: 123979
2011-01-21 16:48:38 +00:00
Douglas Gregor 95273c3a22 Update the reference-binding implementation used for overload
resolution to match the latest C++0x working paper's semantics. The
implementation now matching up with the reference-binding
implementation used for initialization.

llvm-svn: 123977
2011-01-21 16:36:05 +00:00
Douglas Gregor 4edf1c8968 More testing to C++0x [temp.deduct.call]p3
llvm-svn: 123967
2011-01-21 05:24:25 +00:00
Douglas Gregor cba72b1f62 Implement the special template argument deduction rule for T&& in a
call (C++0x [temp.deduct.call]p3).

As part of this, start improving the reference-binding implementation
used in the computation of implicit conversion sequences (for overload
resolution) to reflect C++0x semantics. It still needs more work and
testing, of course.

llvm-svn: 123966
2011-01-21 05:18:22 +00:00
Douglas Gregor 9b175e0512 Add more reference-binding examples from the C++0x working paper, all of which seem to be working fine
llvm-svn: 123955
2011-01-21 01:11:43 +00:00
Douglas Gregor 24f2e8ec00 More work to bring reference binding up to the latest C++0x
specification. In particular, an rvalue reference can bind to an
initializer expression that is an lvalue if the referent type and the
initializer expression type are not reference-related. This is a newer
formulation to the previous "rvalue references can never bind to
lvalues" rule.

llvm-svn: 123952
2011-01-21 00:52:42 +00:00
Douglas Gregor d412fe598b When performing reference binding via a conversion function, perform
type checking based on the actual reference type we're trying to bind
the result to, rather than stripping the reference.

llvm-svn: 123950
2011-01-21 00:27:08 +00:00
Douglas Gregor 56d7eae857 More tests for reference binding in the presence of rvalue
references. Note that we're currently failing reference binding to a
function lvalue.

llvm-svn: 123920
2011-01-20 17:04:36 +00:00
Douglas Gregor 92e460e909 Start refactoring reference binding to more closely match the C++0x
working paper's structure. The only functional change here is that we
now handling binding to array rvalues, which we would previously reject.

llvm-svn: 123918
2011-01-20 16:44:54 +00:00
Anders Carlsson 3f610c75de Diagnose when a virtual member function marked final is overridden.
llvm-svn: 123916
2011-01-20 16:25:36 +00:00
Douglas Gregor 7a2a116bab Add some tests for reference-collapsing and referencing binding
involving rvalue references, to start scoping out what is and what
isn't implemented. In the process, tweak some standards citations,
type desugaring, and teach the tentative parser about && in
ptr-operator.

llvm-svn: 123913
2011-01-20 16:08:06 +00:00
Anders Carlsson 7c812f5a99 When instantiating member functions, propagate whether the member function is marked 'final' and 'override'.
Also, call CheckOverrideControl when instantiating member functions.

llvm-svn: 123900
2011-01-20 06:52:44 +00:00
Anders Carlsson fa8e5d3d67 When checking for functions marked override, ignore dependent contexts.
llvm-svn: 123894
2011-01-20 06:33:26 +00:00