Commit Graph

1671 Commits

Author SHA1 Message Date
Faisal Vali 0374bf0d07 [NFC] Change the evaluation context of a non-type default template argument from Unevaluated to ConstantEvaluated.
This patch emits a more appropriate (but still noisy) diagnostic stream when a lambda-expression is encountered within a non-type default argument. 

For e.g. template<int N = ([] { return 5; }())> int f();

As opposed to complaining that a lambda expression is not allowed in an unevaluated operand, the patch complains about the lambda being forbidden in a constant expression context (which will be allowed in C++17 now that they have been accepted by EWG, unless of course CWG or national bodies (that have so far shown no signs of concern) rise in protest) 

As I start submitting patches for constexpr lambdas (http://wg21.link/P0170R0) under C++1z (OK'd by Richard Smith at Kona), this will be one less change to make.

Thanks!

llvm-svn: 253431
2015-11-18 04:29:22 +00:00
Charles Li e7cbb3ed4f [Lit Test] Updated 34 Lit tests to be C++11 compatible.
Added expected diagnostics new to C++11.
Expanded RUN line to: default, C++98/03 and C++11.

llvm-svn: 253371
2015-11-17 20:25:05 +00:00
Richard Smith 4b213d73d8 Avoid duplicated diagnostic when lookup for a nested-name-specifier fails due to ambiguity.
llvm-svn: 252967
2015-11-12 22:40:09 +00:00
Richard Smith 990668b7d0 DR407: Rationalize how we handle tags being hidden by typedefs. Even with
DR407, the C++ standard doesn't really say how this should work. Here's what we
do (which is consistent with DR407 as far as I can tell):

 * When performing name lookup for an elaborated-type-specifier, a tag
   declaration hides a typedef declaration that names the same type.
 * When performing any other kind of lookup, a typedef declaration hides
   a tag declaration that names the same type.

In any other case where lookup finds both a typedef and a tag (that is, when
they name different types), the lookup will be ambiguous. If lookup finds a
tag and a typedef that name the same type, and finds anything else, the lookup
will always be ambiguous (even if the other entity would hide the tag, it does
not also hide the typedef).

llvm-svn: 252959
2015-11-12 22:04:34 +00:00
Nathan Wilson 68b2b9b3dc Add diagnostics which fall under [dcl.spec.concept]p5
Summary: Diagnose when a function concept declaration has parameter(s)

Reviewers: rsmith, faisalv, aaron.ballman, hubert.reinterpretcast

Subscribers: cfe-commits

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

llvm-svn: 252827
2015-11-11 23:53:35 +00:00
Charles Li 542f04cc4d [Lit Test] Updated 26 Lit tests to be C++11 compatible.
Expected diagnostics have been expanded to vary by C++ dialect.
RUN line has also been expanded to: default, C++98/03 and C++11.

llvm-svn: 252785
2015-11-11 19:34:47 +00:00
Richard Smith e301ba2b48 Add support for GCC's '__auto_type' extension, per the GCC manual:
https://gcc.gnu.org/onlinedocs/gcc/Typeof.html

Differences from the GCC extension:
 * __auto_type is also permitted in C++ (but only in places where
   it could appear in C), allowing its use in headers that might
   be shared across C and C++, or used from C++98
 * __auto_type can be combined with a declarator, as with C++ auto
   (for instance, "__auto_type *p")
 * multiple variables can be declared in a single __auto_type
   declaration, with the C++ semantics (the deduced type must be
   the same in each case)

This patch also adds a missing restriction on applying typeof to
a bit-field, which GCC has historically rejected in C (due to
lack of clarity as to whether the operand should be promoted).
The same restriction also applies to __auto_type in C (in both
GCC and Clang).

This also fixes PR25449.

Patch by Nicholas Allegra!

llvm-svn: 252690
2015-11-11 02:02:15 +00:00
Richard Smith 42b1057244 N3922: direct-list-initialization of an auto-typed variable no longer deduces a
std::initializer_list<T> type. Instead, the list must contain a single element
and the type is deduced from that.

In Clang 3.7, we warned by default on all the cases that would change meaning
due to this change. In Clang 3.8, we will support only the new rules -- per
the request in N3922, this change is applied as a Defect Report against earlier
versions of the C++ standard.

This change is not entirely trivial, because for lambda init-captures we
previously did not track the difference between direct-list-initialization and
copy-list-initialization. The difference was not previously observable, because
the two forms of initialization always did the same thing (the elements of the
initializer list were always copy-initialized regardless of the initialization
style used for the init-capture).

llvm-svn: 252688
2015-11-11 01:36:17 +00:00
Nathan Wilson f22124f531 [Concepts] Add diagnostics which fall under [dcl.spec.concept]p1
Summary: Diagnose when the 'concept' specifier is used on a typedef or function parameter.

Reviewers: rsmith, hubert.reinterpretcast, aaron.ballman, faisalv

Subscribers: cfe-commits

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

llvm-svn: 252061
2015-11-04 18:18:35 +00:00
Nathan Wilson f89306b437 [Concepts] Fixing Concepts TS directory structure; NFC
llvm-svn: 249934
2015-10-10 02:17:39 +00:00
David Majnemer c10b8381f7 Update tests touched by r249656
These test updates almost exclusively around the change in behavior
around enum: enums without a definition are considered incomplete except
when targeting MSVC ABIs.  Since these tests are interested in the
'incomplete-enum' behavior, restrict them to %itanium_abi_triple.

llvm-svn: 249660
2015-10-08 06:31:22 +00:00
Richard Smith e87aeb378d When pretty-printing a C++11 literal operator, don't insert whitespace between
the "" and the suffix; that breaks names such as 'operator""if'. For symmetry,
also remove the space between the 'operator' and the '""'.

llvm-svn: 249641
2015-10-08 00:17:59 +00:00
David Majnemer e14d530497 [Sema] Don't crash when friending an unqualified templated constructor
Unqualified templated constructors cannot be friended and our lack of a
diagnostic led to violated invariants.  Instead, raise a diagnostic when
processing the friend declaration.

This fixes PR20251.

llvm-svn: 248953
2015-09-30 22:07:43 +00:00
Richard Smith a91de375f2 Promote a warning on ill-formed code (redeclaration missing an exception
specification) to an error. No compiler other than Clang seems to allow this,
and it doesn't seem like a useful thing to accept as an extension in general.

The current behavior was added for PR5957, where the problem was specifically
related to mismatches of the exception specification on the implicitly-declared
global operator new and delete. To retain that workaround, we downgrade the
error to an ExtWarn when the declaration is of a replaceable global allocation
function.

Now that this is an error, stop trying (and failing) to recover from a missing
computed noexcept specification. That recovery didn't work, and led to crashes
in code like the added testcase.

llvm-svn: 248867
2015-09-30 00:48:50 +00:00
David Majnemer 54bbae5c0f [Lex] A source-file new-line in a raw string literal results in a new-line
Our string literal parser copied any source-file new-line characters
into the execution string-literal.  This is incorrect if the source-file
new-line character was a \r\n sequence because new-line characters are
merely \n.

llvm-svn: 248392
2015-09-23 16:04:47 +00:00
Nathan Wilson a46106b358 [Concepts] Moving tests to match the corresponding section of the TS
llvm-svn: 247966
2015-09-18 02:50:53 +00:00
NAKAMURA Takumi 1083c40152 thread_local is not implemented for targeting cygwin yet.
llvm-svn: 247204
2015-09-09 22:51:31 +00:00
Nathan Wilson 085b9ff6e2 [Concepts] Add diagnostic; invalid specifier on function or variable concept declaration
Summary: Diagnose variable and function concept declarations when an invalid specifier appears

Reviewers: rsmith, aaron.ballman, faisalv, fraggamuffin, hubert.reinterpretcast

Subscribers: cfe-commits

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

llvm-svn: 247194
2015-09-09 21:48:31 +00:00
Richard Smith d35cb054c9 PR24612: Don't bail out of checking a constexpr function before checking
whether it can ever produce a constant expression in the case where it has a
void return type and no return statements.

llvm-svn: 246347
2015-08-28 22:33:53 +00:00
Nick Lewycky 08426e2098 Clarify the error message when the reason the conversion is not viable is because the returned value does not match the function return type.
llvm-svn: 245979
2015-08-25 22:18:46 +00:00
Serge Pavlov 73c6a2448f Instantiate function declarations in instantiated functions.
If a function declaration is found inside a template function as in:

    template<class T> void f() {
      void g(int x = T::v) except(T::w);
    }

it must be instantiated along with the enclosing template function,
including default arguments and exception specification.

Together with the patch committed in r240974 this implements DR1484.

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

llvm-svn: 245810
2015-08-23 10:22:28 +00:00
Davide Italiano 32cbff7809 [Sema] Be consistent about diagnostic wording: always use "cannot".
Discussed with Richard Smith.

llvm-svn: 245162
2015-08-15 15:23:14 +00:00
Davide Italiano da8a3b903b [Sema] main can't be declared as global variable, in C++.
So, we now reject that. We also warn for any external-linkage global
variable named main in C, because it results in undefined behavior.

PR:	  24309
Differential Revision:	http://reviews.llvm.org/D11658
Reviewed by:	rsmith

llvm-svn: 245051
2015-08-14 14:13:29 +00:00
Richard Smith a534a31c5e [modules] In C++, stop serializing and deserializing a list of declarations in
the identifier table. This is redundant, since the TU-scope lookups are also
serialized as part of the TU DeclContext, and wasteful in a number of ways. We
still emit the decls for PCH / preamble builds, since for those we want
identical results, not merely semantically equivalent ones.

llvm-svn: 242855
2015-07-21 23:54:07 +00:00
David Majnemer 38a50c0a16 [Sema] Emit a better diagnostic when variable redeclarations disagree
We referred to all declaration in definitions in our diagnostic messages
which is can be inaccurate.  Instead, classify the declaration and emit
an appropriate diagnostic for the new declaration and an appropriate
note pointing to the old one.

This fixes PR24116.

llvm-svn: 242190
2015-07-14 20:08:49 +00:00
Adrian Prantl bc068586ac Revert "Revert r241620 and follow-up commits" and move the initialization
of the llvm targets from clang/CodeGen into ClangCheck.cpp and CIndex.cpp.

llvm-svn: 241653
2015-07-08 01:00:30 +00:00
Adrian Prantl 142ec39739 Revert r241620 and follow-up commits while investigating linux buildbot failures.
llvm-svn: 241642
2015-07-07 23:19:46 +00:00
Adrian Prantl e50371b948 Wrap clang modules and pch files in an object file container.
This patch adds ObjectFilePCHContainerOperations uses the LLVM backend
to put the contents of a PCH into a __clangast section inside a COFF, ELF,
or Mach-O object file container.

This is done to facilitate module debugging by makeing it possible to
store the debug info for the types defined by a module alongside the AST.

rdar://problem/20091852

llvm-svn: 241620
2015-07-07 20:11:29 +00:00
Davide Italiano bf0f7757e2 [Sema] Warn when shifting a negative value.
Example:
 % ./clang -Wshift-negative-value emit.c
emit.c:3:14: warning: shifting a negative signed value is undefined [-Wshift-negative-value]
  int a = -1 << 3;
          ~~ ^
1 warning generated.

PR:		24026
Differential Revision:	 http://reviews.llvm.org/D10938
Reviewed by:	rsmith

llvm-svn: 241478
2015-07-06 18:02:09 +00:00
Richard Smith 88fe69ce21 DR1909: Diagnose all invalid cases of a class member sharing its name with the class.
llvm-svn: 241425
2015-07-06 01:45:27 +00:00
Richard Smith a60a6db73f When we see something that looks like a constructor with a return type, only issue one error, not two.
llvm-svn: 241424
2015-07-06 01:04:39 +00:00
David Majnemer 3c20ab2f2c [Sema] Don't crash when deduction fails for decltype(auto)
We didn't check the return result of BuildDecltypeType, resulting in us
crashing when we tried to grab the canonical version of the type.

This fixes PR23995.

llvm-svn: 241131
2015-07-01 00:29:28 +00:00
Meador Inge f0af05c4a5 [Parse] Allow 'constexpr' in condition declarations
This patch implements the functionality specified by DR948.
The changes are two fold.  First, the parser was modified
to allow 'constexpr's to appear in condition declarations
(which was a hard error before).  Second, Sema was modified
to cleanup maybe odr-used declarations by way of a call to
'ActOnFinishFullExpr'.  As 'constexpr's were not allowed in
condition declarations before the cleanup wasn't necessary
(such declarations were always odr-used).

This fixes PR22491.

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

llvm-svn: 240707
2015-06-25 22:06:40 +00:00
David Majnemer fcbdb6ea58 Update clang to take into account the changes to personality fns
llvm-svn: 239941
2015-06-17 20:53:19 +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 86dec39c0a PR20073: promote "dereference of 'void*'" from Extension to ExtWarn.
llvm-svn: 237652
2015-05-19 01:41:12 +00:00
Richard Trieu d3967635bc Fix typo from r237482. "to reference of type" --> "to reference to type"
llvm-svn: 237507
2015-05-16 01:39:39 +00:00
Richard Trieu f956a49e6d When emitting a dropped qualifier error, show which qualifiers are dropped.
llvm-svn: 237505
2015-05-16 01:27:03 +00:00
Richard Trieu 0ff51f39de Reverse the order of types in the reference dropping qualifiers error.
The error has the form ... 'int' ... 'const int' ... dropped qualifiers.  At
first glance, it appears that the const qualifier is added.  Reverse the types
so that the second type is less qualified than the first.

llvm-svn: 237482
2015-05-15 22:07:49 +00:00
Richard Smith a462b4c9ac DR295: cv-qualifiers on function types are ignored in C++.
llvm-svn: 237383
2015-05-14 19:10:42 +00:00
Richard Smith 2d5814c2d4 Update cxx_dr_status to latest issues list.
llvm-svn: 237382
2015-05-14 19:07:47 +00:00
Richard Smith c38498f046 PR23334: Perform semantic checking of lambda capture initialization in the right context.
Previously we'd try to perform checks on the captures from the middle of
parsing the lambda's body, at the point where we detected that a variable
needed to be captured. This was wrong in a number of subtle ways. In
PR23334, we couldn't correctly handle the list of potential odr-uses
resulting from the capture, and our attempt to recover from that resulted
in a use-after-free.

We now defer building the initialization expression until we leave the lambda
body and return to the enclosing context, where the initialization does the
right thing. This patch only covers lambda-expressions, but we should apply
the same change to blocks and captured statements too.

llvm-svn: 235921
2015-04-27 21:27:54 +00:00
David Majnemer bc4cc14cd7 [Sema] Don't crash if array bound calculation overflowed constexpr array
We didn't correctly expect a QualifiedTypeLoc when faced with fixing a
variable array type into a constant array type.

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

llvm-svn: 235251
2015-04-18 04:55:51 +00:00
Nico Weber 337d5aa58f Move fixit for const init from note to diag, weaken to warning in MS mode.
r235046 turned "extern __declspec(selectany) int a;" from a declaration into
a definition to fix PR23242 (required for compatibility with mc.exe output).
However, this broke parsing Windows headers: A  d3d11 headers contain something
like

  struct SomeStruct {};
  extern const __declspec(selectany) SomeStruct some_struct;

This is now a definition, and const objects either need an explicit default
ctor or an initializer so this errors out with 

  d3d11.h(1065,48) :
    error: default initialization of an object of const type
           'const CD3D11_DEFAULT' without a user-provided default constructor

(cl.exe just doesn't implement this rule, independent of selectany.)

To work around this, weaken this error into a warning for selectany decls
in microsoft mode, and recover with zero-initialization.

Doing this is a bit hairy since it adds a fixit on an error emitted
by InitializationSequence – this means it needs to build a correct AST, which
in turn means InitializationSequence::Failed() cannot return true when this
fixit is applied. As a workaround, the patch adds a fixit member to
InitializationSequence, and InitializationSequence::Perform() prints the
diagnostic if the fixit member is set right after its call to Diagnose.
That function is usually called when InitializationSequences are used –
InitListChecker::PerformEmptyInit() doesn't call it, but the InitListChecker
case never performs default-initialization, so this is technically OK.

This is the alternative, original fix for PR20208 that got reviewed in the
thread "[patch] Improve diagnostic on default-initializing const variables
(PR20208)".  This change basically reverts r213725, adds the original fix for
PR20208, and makes the error a warning in Microsoft mode.

llvm-svn: 235166
2015-04-17 08:32:38 +00:00
Richard Trieu af7d76c720 Improve the error message for assigning to read-only variables.
Previously, many error messages would simply be "read-only variable is not
assignable"  This change provides more information about why the variable is
not assignable, as well as note to where the const is located.

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

llvm-svn: 234677
2015-04-11 01:53:13 +00:00
Aaron Ballman 8aee642909 Generate a diagnostic when a catch handler cannot execute due to class hierarchy inversion with regards to other catch handlers for the same block.
llvm-svn: 234375
2015-04-08 00:05:29 +00:00
Eric Christopher 6e11073b3e Unify warnings/errors from "maybe you meant" to "did you mean".
llvm-svn: 233981
2015-04-02 22:10:06 +00:00
Benjamin Kramer 6dcddc21f8 Mark DR777 only as fixed in clang SVN.
llvm-svn: 233391
2015-03-27 17:38:35 +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