Commit Graph

371 Commits

Author SHA1 Message Date
Douglas Gregor ab6bc1d13e Make the -Wc++11-compat warnings ignored by default, so we don't break
valid C++98/03 code. However, add these warnings to -Wall, for those
who obviously already like clean code.

llvm-svn: 142903
2011-10-25 03:07:45 +00:00
Peter Collingbourne 7d33cd3a2f Fix grammar for C++11 alignment specifiers, and add a few FIXMEs.
llvm-svn: 142760
2011-10-23 20:07:52 +00:00
Peter Collingbourne 9f58d7b789 Diagnose unexpanded parameter packs in member initialisers (including
in-class member initialisers).

llvm-svn: 142758
2011-10-23 18:59:44 +00:00
Richard Smith f411196d15 'extern template' is a C++11 feature. Add an Extension for C++98 (this matches
gcc's behaviour), and a -Wc++98-compat-pedantic warning for C++11.

llvm-svn: 142597
2011-10-20 18:35:58 +00:00
David Blaikie 651c73ce78 Fix pr9789, assert-on-invalid while instantiating an (invalid) class template with a non-final parameter pack. Also improve the warning for non-final parameter packs in this scenario so it only fires once, rather than once for every template parameter after the non-final parameter pack.
llvm-svn: 142473
2011-10-19 05:19:50 +00:00
Richard Smith 465841e48c [temp.explicit]p1: constexpr cannot be specified in explicit instantiations.
llvm-svn: 141982
2011-10-14 19:58:02 +00:00
Richard Smith 9ca5c42582 Update all tests other than Driver/std.cpp to use -std=c++11 rather than
-std=c++0x. Patch by Ahmed Charles!

llvm-svn: 141900
2011-10-13 22:29:44 +00:00
Douglas Gregor ebcfbb5d22 When we determine that a function template specialization produced as
part of template argument deduction is ill-formed, we mark it as
invalid and treat it as a deduction failure. If we happen to find that
specialization again, treat it as a deduction failure rather than
silently building a call to the declaration.

Fixes PR11117, a marvelous bug where deduction failed after creating
an invalid specialization, causing overload resolution to pick a
different candidate. Then we performed a similar overload resolution
later, and happily picked the invalid specialization to
call... resulting in a silent link failure.

llvm-svn: 141809
2011-10-12 20:35:48 +00:00
Douglas Gregor 205d044552 Switch diagnostic text from "C++0x" over to "C++11".
We'd also like for "C++11" or "c++11" to be used for the warning
groups, but without removing the old warning flags. Patches welcome;
I've run out of time to work on this today.

llvm-svn: 141801
2011-10-12 19:26:40 +00:00
John McCall 50a2c2c19d Catch placeholder types in DefaultLvalueConversion
and DefaultFunctionArrayLvalueConversion.  To prevent
significant regression for should-this-be-a-call fixits,
and to repair some such regression from the introduction of
bound member placeholders, make those placeholder checks
try to build calls appropriately.  Harden the build-a-call
logic while we're at it.

llvm-svn: 141738
2011-10-11 23:14:30 +00:00
Douglas Gregor ab96bcf6ea When substituting into a sizeof parameter pack expression in a context
where we can't expand (i.e., multi-level substitution), be sure to
substitute the pack with its level-reduced pack. Fixes PR10230.

llvm-svn: 141568
2011-10-10 18:59:29 +00:00
Douglas Gregor 0c83c8128b Per the note in C++0x [temp.deduct.call]p4, don't attempt template
argument deduction against a function parameter that has no deducible
template parameters in it. Fixes PR8598.

llvm-svn: 141517
2011-10-09 22:06:46 +00:00
Douglas Gregor e9d075e434 A friend template specialization is also dependent if any of its
template arguments are dependent. Fixes PR10913.

llvm-svn: 141515
2011-10-09 20:59:17 +00:00
Sebastian Redl 22653bac1a Declare and define implicit move constructor and assignment operator.
This makes the code duplication of implicit special member handling even worse,
but the cleanup will have to come later. For now, this works.
Follow-up with tests for explicit defaulting and enabling the __has_feature
flag to come.

llvm-svn: 138821
2011-08-30 19:58:05 +00:00
Richard Smith 7b8c3c91f4 PR10359: Template declarations which define classes are not permitted to also contain declarators. Previously we would accept code like this:
template<typename T> struct S { } f() { return 0; }

This case now produces a missing ';' diagnostic, since that seems like a much more likely error than an attempt to declare a function or variable in addition to the class template.

Treat this 

llvm-svn: 135195
2011-07-14 21:35:26 +00:00
Chandler Carruth c933221826 Factor out (some of) the checking for invalid forms of pointer
arithmetic into a couple of common routines. Use these to make the
messages more consistent in the various contexts, especially in terms of
consistently diagnosing binary operators with invalid types on both the
left- and right-hand side. Also, improve the grammar and wording of the
messages some, handling both two pointers and two (different) types.

The wording of function pointer arithmetic diagnostics still strikes me
as poorly phrased, and I worry this makes them slightly more awkward if
more consistent. I'm hoping to fix that with a follow-on patch and test
case that will also make them more helpful when a typedef or template
type parameter makes the type completely opaque.

Suggestions on better wording are very welcome, thanks to Richard Smith
for some initial help on that front.

llvm-svn: 133906
2011-06-27 08:02:19 +00:00
Chandler Carruth 53e61b05ce Accept no-return stripping conversions for pointer type arguments after
deducing template parameter types. Recently Clang began enforcing the
more strict checking that the argument type and the deduced function
parameter type (after substitution) match, but that only consideres
qualification conversions.

One problem with this patch is that we check noreturn conversions and
qualification conversions independently. If a valid conversion would
require *both*, perhaps interleaved with each other, it will be
rejected. If this actually occurs (I'm not yet sure it does) and is in
fact a problem (I'm not yet sure it is), there is a FIXME to implement
more intelligent conversion checking.

However, this step at least allows Clang to resume accepting valid code
we're seeing in the wild.

llvm-svn: 133327
2011-06-18 01:19:03 +00:00
Douglas Gregor e65aacb9e9 Implement the consistency checking for C++ [temp.deduct.call]p3, which
checks that the deduced argument type for a function call matches the
actual argument type provided. The only place we've found where the
consistency checking should actually cause template argument deduction
failure is due to qualifier differences that don't fall into the realm
of qualification conversions (which are *not* checked when we
initially perform deduction). However, we're performing the full
checking as specified in the standard to ensure that no other cases
exist.

Fixes PR9233 / <rdar://problem/9039590>.

llvm-svn: 133163
2011-06-16 16:50:48 +00:00
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
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 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
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
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
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
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
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
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
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
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
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
Anders Carlsson 479d6f51e3 Pass -fexceptions to all tests that use try/catch/throw.
llvm-svn: 126037
2011-02-19 19:23:03 +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
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 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 54e462ac6e Rvalue references for *this: tentative parsing and template argument deduction.
llvm-svn: 124295
2011-01-26 16:50:54 +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
Anders Carlsson e973899f46 A member function template cannot be virtual.
llvm-svn: 124031
2011-01-22 14:43:56 +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