Commit Graph

8146 Commits

Author SHA1 Message Date
David Blaikie ae12b18ad8 Suppress macro expansion of NULL in NULL warnings.
For "int i = NULL;" we would produce:

null.cpp:5:11: warning: implicit conversion of NULL constant to integer [-Wconversion]
  int i = NULL;
      ~   ^~~~
null.cpp:1:14: note: expanded from macro 'NULL'
\#define NULL __null
              ^~~~~~

But we really shouldn't trace that macro expansion back into the header, yet we
still want macro back traces for code like this:

\#define FOO NULL
int i = FOO;

or

\#define FOO int i = NULL;
FOO

While providing appropriate tagging at different levels of the expansion, etc.

The included test case exercises these cases & does some basic validation (to
ensure we don't have macro expansion notes where we shouldn't, and do where we
should) - but doesn't go as far as to validate the source location/ranges
used in those notes and warnings.

llvm-svn: 152940
2012-03-16 20:30:12 +00:00
Nick Lewycky af0cc7fd27 Skip through transparent contexts when deciding where to add a friend function.
This fixes g++.dg/parse/friend5.C.

llvm-svn: 152938
2012-03-16 19:51:19 +00:00
David Chisnall 07518f249f Warn on flexible array members when in C89 mode, with -pedantic.
This fixes PR 4307.

Patch by Eitan Adler!

llvm-svn: 152918
2012-03-16 12:15:37 +00:00
Sebastian Redl 1918166de7 Support deducing template arguments from nested initializer lists. PR12119.
llvm-svn: 152848
2012-03-15 21:40:51 +00:00
David Blaikie e7fd58006d Provide the specific target type in the -Wnull-conversion warning.
llvm-svn: 152835
2012-03-15 20:48:26 +00:00
Richard Smith eece8c3993 Remove a variable rendered unused by r152750.
llvm-svn: 152758
2012-03-15 00:22:18 +00:00
Richard Smith 4b38ded66a Instantiating a class template should not instantiate the definition of any
scoped enumeration members. Later uses of an enumeration temploid as a nested
name specifier should cause its instantiation. Plus some groundwork for
explicit specialization of member enumerations of class templates.

llvm-svn: 152750
2012-03-14 23:13:10 +00:00
Nick Lewycky fcd5e7a160 When emitting a diagnostic about two-phase name lookup, don't do useless
qualified name lookups into transparent contexts.

llvm-svn: 152739
2012-03-14 20:41:00 +00:00
Douglas Gregor 5c3cc42342 Minor cleanup in attribute-related diagnostics, from Alexander Kornienko!
llvm-svn: 152725
2012-03-14 16:55:17 +00:00
Daniel Dunbar d671ab94fe [Sema] Fix SemaDiagnosticBuilder to be inline.
- As with DiagnosticBuilder, it is very important that SemaDiagnosticBuilder be
   completely inline to ensure that the compiler can rip it apart and sink it to
   registers.

This is good for another 30k reduction in code size.

llvm-svn: 152708
2012-03-14 09:49:32 +00:00
Daniel Dunbar a25002f572 Spelling.
llvm-svn: 152644
2012-03-13 18:30:54 +00:00
James Molloy e943003c09 Ensure that default arguments are handled correctly in sub scopes. For example:
void f () {
  int g (int a, int b=4);
  {
    int g(int a, int b=5);
  }
}

should compile.

llvm-svn: 152621
2012-03-13 08:55:35 +00:00
Richard Smith d0e1c95dcc Implement [temp.param]p5: the top-level cv-qualifiers on a non-type template
parameter's declaration are ignored when determining the parameter's type.

llvm-svn: 152619
2012-03-13 07:21:50 +00:00
Richard Smith 9479a2e35e PR11850 + duplicates: don't assume that a function parameter pack expansion is
at the end of the parameter list.

llvm-svn: 152618
2012-03-13 06:56:52 +00:00
Richard Smith 84208dcf02 PR11925: A function can't have a variably-modified return type. Not even in C++.
llvm-svn: 152615
2012-03-13 05:56:40 +00:00
Nick Lewycky 2bd636f589 It never makes sense to do a lookup into a LinkageSpecDecl, so assert that we
don't, and clean up the places that do it.

The change to ASTWriter is surprising, but the deleted code is a no-op as of
r152608.

llvm-svn: 152609
2012-03-13 04:12:34 +00:00
Richard Smith 05afe5e084 Fix PR10447: lazily building name lookup tables for DeclContexts was broken.
The deferred lookup table building step couldn't accurately tell which Decls
should be included in the lookup table, and consequently built different tables
in some cases.

Fix this by removing lazy building of DeclContext name lookup tables. In
practice, the laziness was frequently not worthwhile in C++, because we
performed lookup into most DeclContexts. In C, it had a bit more value,
since there is no qualified lookup.

In the place of lazy lookup table building, we simply don't build lookup tables
for function DeclContexts at all. Such name lookup tables are not useful, since
they don't capture the scoping information required to correctly perform name
lookup in a function scope.

The resulting performance delta is within the noise on my testing, but appears
to be a very slight win for C++ and a very slight loss for C. The C performance
can probably be recovered (if it is a measurable problem) by avoiding building
the lookup table for the translation unit.

llvm-svn: 152608
2012-03-13 03:12:56 +00:00
Argyrios Kyrtzidis e7f3ef39bf [Sema] Prefer to use ObjCInterfaceDecl's protocol_begin()/protocol_end() iterators instead of
ObjCInterfaceDecl::getReferencedProtocols(), because the iterators are safe to use
even if the caller did not check that the interface is a definition.

llvm-svn: 152597
2012-03-13 01:09:41 +00:00
Argyrios Kyrtzidis 3b60cffa22 Fix crash at @implementation with a forward reference as base class.
rdar://11020003

llvm-svn: 152596
2012-03-13 01:09:36 +00:00
John McCall 5fa2ef4445 Alternate fix to PR12248: put Sema in charge of special-casing
the diagnostic for assigning to a copied block capture.  This has
the pleasant side-effect of letting us special-case the diagnostic
for assigning to a copied lambda capture as well, without introducing
a new non-modifiable enumerator for it.

llvm-svn: 152593
2012-03-13 00:37:01 +00:00
Douglas Gregor 8409ccd8f6 C++11 [temp.deduct.call]p6 tweak: when given a set of overlaoded
functions that includes an explicit template argument list, perform
an inner deduction against each of the function templates in that list
and, if successful, use the result of that deduction for the outer
template argument deduction. Fixes PR11713.

llvm-svn: 152575
2012-03-12 21:09:16 +00:00
Argyrios Kyrtzidis b15def221d [Sema] -Add an invalid objc category to the DeclContext so that it can be
serialized
-Don't add methods of invalid objc containers to the global method pool.
 This protects us from trying to serialize a method whose container was not
 serialized.

Part of rdar://11007039.

llvm-svn: 152566
2012-03-12 18:34:26 +00:00
Jordy Rose 8986c599b4 ObjCBoolLiterals (__objc_yes/__objc_no) behave like C++ booleans (true/false). They are NOT objects.
llvm-svn: 152564
2012-03-12 17:53:02 +00:00
Richard Smith bfdb108fc5 Fix parsing of trailing-return-type. Types are syntactically prohibited from
being defined here: [] () -> struct S {} does not define struct S.

In passing, implement DR1318 (syntactic disambiguation of 'final').

llvm-svn: 152551
2012-03-12 08:56:40 +00:00
David Blaikie bbafb8a745 Unify naming of LangOptions variable/get function across the Clang stack (Lex to AST).
The member variable is always "LangOpts" and the member function is always "getLangOpts".

Reviewed by Chris Lattner

llvm-svn: 152536
2012-03-11 07:00:24 +00:00
Douglas Gregor 194ea69d62 When template argument deduction is ignoring qualifiers, perform deep
structural comparison of non-dependent types. Otherwise, we end up
rejecting cases where the non-dependent types don't match due to
qualifiers in, e.g., a pointee type. Fixes PR12132.

llvm-svn: 152529
2012-03-11 03:29:50 +00:00
Douglas Gregor 50a3cdddda When determining whether an identifier followed by a '<' in a member
access expression is the start of a template-id, ignore function
templates found in the context of the entire postfix-expression. Fixes
PR11856.

llvm-svn: 152520
2012-03-10 23:52:41 +00:00
David Blaikie 631a486e6a Fix crash & accepts-invalid for array of arrays of user defined type.
Test case/other help by Richard Smith.
Code review by John McCall.

llvm-svn: 152519
2012-03-10 23:40:02 +00:00
Richard Smith 5731c75414 PR12225: The requirement that literal operators be namespace-scope functions
does not imply that such functions can't be declared at block scope.

llvm-svn: 152509
2012-03-10 22:18:57 +00:00
John McCall 113bee0536 Remove BlockDeclRefExpr and introduce a bit on DeclRefExpr to
track whether the referenced declaration comes from an enclosing
local context.  I'm amenable to suggestions about the exact meaning
of this bit.

llvm-svn: 152491
2012-03-10 09:33:50 +00:00
Nick Lewycky f604212a44 Slightly tweak this condition. "isTransparentContext()" was checking whether an
enum is scoped or not, which is not relevant here. Instead, phrase the loop in
the same terms that the standard uses, instead of this awkward set of
conditions that is *nearly* equal.

llvm-svn: 152489
2012-03-10 07:47:07 +00:00
Nick Lewycky d9e1e57e2a Could not find this in C99. Perhaps this rule comes from a DR, but in any case
please annotate it with a note explaining why this wrong-seeming behaviour is
correct.

llvm-svn: 152488
2012-03-10 07:45:33 +00:00
Douglas Gregor d2f7007e09 Only make a call to a copy constructor elidable if in fact we are
doing a copy. Fixes PR12139.

llvm-svn: 152485
2012-03-10 06:53:13 +00:00
Argyrios Kyrtzidis 224ec821da [Sema] A tag decl that is marked as invalid and is used in a decl-spec,
should not impede creating a proper TypeLoc info for the decl-spec.

This improves our semantic error recovery.

llvm-svn: 152481
2012-03-10 03:20:58 +00:00
Douglas Gregor dfa5b22238 Qualifiers on a canonical array type go on the outermost type, not the
innermost type. Fixes PR12142.

llvm-svn: 152456
2012-03-10 00:29:33 +00:00
Daniel Dunbar 900ceade87 [Sema] Fix a diag change to include a range that appeared intended, but never
actually happened.

llvm-svn: 152442
2012-03-09 21:38:22 +00:00
Argyrios Kyrtzidis 2559629c5b Improve our semantic error recovery.
When an error made a record member invalid, the record would stay as "isBeingDefined" and
not "completeDefinition". Even easily recoverable errors ended up propagating records in
such "beingDefined" state, for example:

struct A {
  ~A() const; // expected-error {{'const' qualifier is not allowed on a destructor}}
};
struct B : A {}; // A & B would stay as "not complete definition" and "being defined".

This weird state was impending lookups in the records and hitting assertion in the ASTWriter.

Part of rdar://11007039

llvm-svn: 152432
2012-03-09 20:10:30 +00:00
Daniel Dunbar eda65572bb [Sema] Remove dead getSourceRange() call, caught by Clang after marking
LLVM_READONLY.

llvm-svn: 152428
2012-03-09 20:02:47 +00:00
Fariborz Jahanian c8a322a407 lldb support: under debugger support flag, when sending message
to forward class, and assigning to an 'id' type var, message
sends default to 'id'. // rdar"//10988847

llvm-svn: 152420
2012-03-09 18:47:16 +00:00
Daniel Dunbar 62ee6417ac [AST/Sema/libclang] Replace getSourceRange().getBegin() with getLocStart().
- getSourceRange().getBegin() is about as awesome a pattern as .copy().size().

I already killed the hot paths so this doesn't seem to impact performance on my
tests-of-the-day, but it is a much more sensible (and shorter) pattern.

llvm-svn: 152419
2012-03-09 18:35:03 +00:00
Hans Wennborg aa8c61cf94 -Wformat-non-iso: warn about positional arguments (pr12017)
This renames the -Wformat-non-standard flag to -Wformat-non-iso,
rewords the current warnings a bit (pointing out that a format string
is not supported by ISO C rather than being "non standard"),
and adds a warning about positional arguments.

llvm-svn: 152403
2012-03-09 10:10:54 +00:00
Richard Smith 768ceccc75 Literal operators can't have default arguments.
llvm-svn: 152394
2012-03-09 08:16:22 +00:00
Richard Smith bcc22fc4e1 Support for raw and template forms of numeric user-defined literals,
and lots of tidying up.

llvm-svn: 152392
2012-03-09 08:00:36 +00:00
John McCall ef42902816 Perform l2r conversions on delete operands before doing
type-analysis;  otherwise, we just completely do the
wrong thing for placeholders.

llvm-svn: 152375
2012-03-09 04:08:29 +00:00
Daniel Dunbar 9d35581907 [AST] Reduce Decl::getASTContext() calls.
- This function is not at all free; pass it around along some hot paths instead
   of recomputing it deep inside various VarDecl methods.

llvm-svn: 152363
2012-03-09 01:51:51 +00:00
John McCall 85110b47c8 Don't crash when a statement in a block is ill-formed but
introduces cleanups anyway.

llvm-svn: 152345
2012-03-08 22:00:17 +00:00
Sebastian Redl 04fe1bf52e Turn explicit construction of temporaries using initializer list syntax into CXXTemporaryObjectExprs, not just CXXConstructExprs, which have a worrying tendency to vanish. Fixes PR12167.
llvm-svn: 152340
2012-03-08 21:05:45 +00:00
Rafael Espindola df88f6fe98 Replace MarkVarRequired with a more generic
HandleCXXStaticMemberVarInstantiation. Suggested by Argyrios.

llvm-svn: 152320
2012-03-08 15:51:03 +00:00
Richard Smith 39570d0020 Add support for cooked forms of user-defined-integer-literal and
user-defined-floating-literal. Support for raw forms of these literals
to follow.

llvm-svn: 152302
2012-03-08 08:45:32 +00:00
Richard Smith 0df56f4a90 Implement C++11 [lex.ext]p10 for string and character literals: a ud-suffix not
starting with an underscore is ill-formed.

Since this rule rejects programs that were using <inttypes.h>'s macros, recover
from this error by treating the ud-suffix as a separate preprocessing-token,
with a DefaultError ExtWarn. The approach of treating such cases as two tokens
is under discussion for standardization, but is in any case a conforming
extension and allows existing codebases to keep building while the committee
makes up its mind.

Reword the warning on the definition of literal operators not starting with
underscores (which are, strangely, legal) to more explicitly state that such
operators can't be called by literals. Remove the special-case diagnostic for
hexfloats, since it was both triggering in the wrong cases and incorrect.

llvm-svn: 152287
2012-03-08 02:39:21 +00:00