Commit Graph

625 Commits

Author SHA1 Message Date
Richard Smith 8acb4280c5 Factor out exception specification information from
FunctionProtoType::ExtProtoInfo. Most of the users of these fields don't care
about the other ExtProtoInfo bits and just want to talk about the exception
specification.

llvm-svn: 214450
2014-07-31 21:57:55 +00:00
Kaelyn Takata b04846b4cd Add another keyword-selection flag to CorrectionCandidateCallback.
The new flag, WantFunctionLikeCasts, covers a subset of the keywords
covered by WantTypeSpecifiers that can be used in casts that look like
function calls, e.g. "return long(5);", while excluding the keywords
like "enum" and "const" that would be included when WantTypeSpecifiers
is true but cannot be used in something that looks like a function call.

llvm-svn: 214109
2014-07-28 18:14:02 +00:00
Aaron Ballman 1e606f4d46 Switching some iterator-based for loops to use range-based for loops. No functional changes intended.
llvm-svn: 213098
2014-07-15 22:03:49 +00:00
Aaron Ballman 2a89e8526a Added the pack_elements range accessor. Refactoring some for loops to use range-based for loops instead. No functional changes intended.
llvm-svn: 213095
2014-07-15 21:32:31 +00:00
Nikola Smiljanic 1c1256830d Fix typos.
llvm-svn: 212589
2014-07-09 05:42:35 +00:00
Nick Lewycky 9ea8efaf92 Propagate isAddressOfMember into typo correction so that we don't correct &qualified-id into &unqualified-id. Also make sure to set the naming class when we find the qualified-id in a different class than the nested name specifier specified so far. Fixes PR19681!
llvm-svn: 211551
2014-06-23 22:57:51 +00:00
Kaelyn Takata a95ebc6801 Fix the caller of checkCorrectionVisibility too.
That's what I get for hurredly splitting the small change out of a much
bigger change that had moved where checkCorrectionVisibility was being
called.

llvm-svn: 211134
2014-06-17 23:47:29 +00:00
Kaelyn Takata 61df4a787e Remove an unused argument from checkCorrectionVisibility.
llvm-svn: 211133
2014-06-17 23:41:33 +00:00
Hans Wennborg 660101302e Fix the VS2012 build.
It didn't handle the in-class member initializer and compound literal.

llvm-svn: 210707
2014-06-11 21:24:13 +00:00
Kaelyn Takata cd7c3a9de4 Add some comments to TypoCorrectionConsumer.
Also move the constructor for NamespaceSpecifierSet out of line to
improve the class' readability. I meant to do these two things while
cleaning up the previous TypoCorrectionConsumer changes and have them
folded into those changes.

No functionality changed.

llvm-svn: 210686
2014-06-11 18:33:46 +00:00
Kaelyn Takata 7dcc0e6f57 Sink SpecifierInfo into the only class that uses it.
SpecifierInfo is not used outside of NamespaceSpecifierSet except
indirectly through NamespaceSpecifierSet's iterator, so clean up the
code a bit by moving SpecifierInfo into NamespaceSpecifierSet. Also drop
SpecifierInfo's trivial yet verbose constructor since brace
initiialization is sufficient in the only two places the constructor was
being explicitly called.

No functionality changed.

llvm-svn: 210672
2014-06-11 18:07:08 +00:00
Kaelyn Takata a5bdbc840c Make a couple of helper classes private to TypoCorrectionConsumer.
The SpecifierInfo and NamespaceSpecifierSet are now only used by
TypoCorrectionConsumer, so treat them as the implementation details of
TypoCorrectionConsumer that they are. Also make NamespaceSpecifierSet's
method names more style guide compliant.

No functionality changed.

llvm-svn: 210671
2014-06-11 18:07:05 +00:00
Kaelyn Takata 9e2931ec60 Clean up the TypoCorrectionConsumer's interface a bit.
No functionality changed.

llvm-svn: 210670
2014-06-11 18:07:03 +00:00
Kaelyn Takata 68fdd59b31 Move TypoCorrection filtering into the TypoCorrectionConsumer and make it incremental.
The only external/visible functional change that fell out of this
refactoring is that there was one less case where the typo caching
and/or counting didn't work properly. The result is that a test case
had to be moved from typo-correction.cpp to typo-correction-pt2.cpp
to avoid the hard-coded limit on per file/TU typo correction attempts.

llvm-svn: 210669
2014-06-11 18:07:01 +00:00
Kaelyn Takata 0fc7519314 Move a few classes to be before TypoCorrectionConsumer.
This is in preparation for moving TypoCorrection filtering
into the TypoCorrectionConsumer, to separate out some of the purely
mechanical churn. It also makes some of the method names in
NamespaceSpecifierSet be more style guide compliant.

No functionality changed.

llvm-svn: 210668
2014-06-11 18:06:56 +00:00
Kaelyn Takata 73429fd4a6 Remove a redundant conditional when caching typo failures.
No functionality change.

llvm-svn: 210583
2014-06-10 21:03:49 +00:00
Craig Topper c3ec149bb2 [C++11] Use 'nullptr'. Sema edition.
llvm-svn: 209613
2014-05-26 06:22:03 +00:00
John Thompson 2309b15cb0 fmodules-search-all: Removed dead code and added some comments.
llvm-svn: 208259
2014-05-07 22:47:08 +00:00
Richard Smith 3d23c42029 If an instantiation of a template is required to be a complete type, check
whether the definition of the template is visible rather than checking whether
the instantiated definition happens to be in an imported module.

llvm-svn: 208150
2014-05-07 02:25:43 +00:00
Alp Toker b6cc592ea3 Fix a bunch of mislayered clang/Lex includes from Sema
llvm-svn: 207896
2014-05-03 03:45:55 +00:00
John Thompson 2d94bbb0c0 Quick fix for layering that broke shared library build.
llvm-svn: 207011
2014-04-23 19:04:32 +00:00
John Thompson 2255f2ce90 Initial implementation of -modules-earch-all option, for searching for symbols in non-imported modules.
llvm-svn: 206977
2014-04-23 12:57:01 +00:00
Richard Smith 100b24abc5 Implement [over.match.oper]p3 properly, by filtering the non-candidates out
when building the candidate set, rather than trying to contort name lookup into
handling this.

llvm-svn: 206436
2014-04-17 01:52:14 +00:00
Richard Smith 688866ba3e PR19452: Implement more of [over.match.oper]p3's restrictions on which non-member overloaded operators can be found when no operand is of class type. We used to fail to implement this rule if there was an operand of dependent type.
llvm-svn: 206435
2014-04-17 01:12:17 +00:00
Richard Smith 83e78f5c3c Fix handling of redeclaration lookup for using declarations, where the prior
declaration is not visible. Previously we didn't find hidden friend names in
this redeclaration lookup, because we forgot to treat it as a redeclaration
lookup. Conversely, we did find some local extern names, but those don't
actually conflict with a namespace-scope using declaration, because the only
conflicts we can get are scope conflicts, not conflicts due to the entities
being members of the same namespace.

llvm-svn: 206011
2014-04-11 01:03:38 +00:00
Kaelyn Takata fb271f0cab Try harder about not suggesting methods as corrections when they
obviously won't work. Specifically, don't suggest methods (static or
not) from unrelated classes when the expression is a method call
through a specific object.

llvm-svn: 205653
2014-04-04 22:16:30 +00:00
Richard Smith f97ad226dc Fix self-referential comment.
llvm-svn: 205340
2014-04-01 18:33:50 +00:00
Kaelyn Uhrain ec2629964e Be a bit smarter about what nested name qualifiers to allow when
performing typo correction on very short (1 or 2 char) identifiers.

llvm-svn: 204525
2014-03-21 21:54:25 +00:00
Kaelyn Uhrain bbfc05727b [C++11] Simplify some loops in Sema::CorrectTypo as range-based for loops.
llvm-svn: 204524
2014-03-21 21:54:22 +00:00
Aaron Ballman 804a7fb7ba [C++11] Replacing DeclContext iterators using_directives_begin() and using_directives_end() with iterator_range using_directives(). Updating all of the usages of the iterators with range-based for loops, and removing the no-longer-needed iterator versions. Also used as an opportunity to normalize the name from getUsingDirectives() to using_directives().
llvm-svn: 204061
2014-03-17 17:14:12 +00:00
Aaron Ballman 5df6aa465e [C++11] Replacing Scope iterators using_directives_begin() and using_directives_end() with iterator_range using_directives(). Updating all of the usages of the iterators with range-based for loops, and removing the no-longer-needed iterator versions.
llvm-svn: 204053
2014-03-17 17:03:37 +00:00
Aaron Ballman 35c5495bbb [C++11] Replacing Scope iterators decl_begin() and decl_end() with iterator_range decls(). Updating all of the usages of the iterators with range-based for loops, and removing the no-longer-needed iterator versions.
llvm-svn: 204052
2014-03-17 16:55:25 +00:00
Aaron Ballman 83731469a1 [C++11] Replacing ObjCObjectPointerType iterators qual_begin() and qual_end() with iterator_range quals(). Updating all of the usages of the iterators with range-based for loops.
llvm-svn: 204048
2014-03-17 16:14:00 +00:00
Aaron Ballman 40bd0aaf68 [C++11] Replacing FunctionProtoType iterators param_type_begin() and param_type_end() with iterator_range param_types(). Updating all of the usages of the iterators with range-based for loops.
llvm-svn: 204045
2014-03-17 15:23:01 +00:00
Richard Smith 594461f02c Call RequireCompleteType when performing ADL even if the type is already
complete. We hook into this check from a couple of other places (modules,
debug info) so it's not OK to elide the check if the type was already
complete.

llvm-svn: 203978
2014-03-14 22:07:27 +00:00
Aaron Ballman e42430ea31 [C++11] Removing the types_begin() and types_end() APIs and replacing with a range-only types() API.
llvm-svn: 203971
2014-03-14 21:11:14 +00:00
Aaron Ballman 576114e676 [C++11] Replacing DeclContext iterators lookups_begin() and lookups_end() with iterator_range lookups(). Similar for noload_lookups(). Updating all of the usages of the iterators with range-based for loops.
llvm-svn: 203933
2014-03-14 15:28:49 +00:00
Aaron Ballman 19a417699f [C++11] Replacing ObjCCategoryDecl iterators protocol_begin() and protocol_end() with iterator_range protocols(). Updating all of the usages of the iterators with range-based for loops.
llvm-svn: 203922
2014-03-14 12:55:57 +00:00
Aaron Ballman 0f6e64d505 [C++11] Replacing ObjCProtocolDecl iterators protocol_begin() and protocol_end() with iterator_range protocols(). Updating all of the usages of the iterators with range-based for loops.
llvm-svn: 203863
2014-03-13 22:58:06 +00:00
Aaron Ballman 3fe486a332 [C++11] Replacing ObjCInterfaceDecl iterators visible_categories_begin() and visible_categories_end() with iterator_range visible_categories(). Updating all of the usages of the iterators with range-based for loops.
llvm-svn: 203851
2014-03-13 21:23:55 +00:00
Aaron Ballman a9f49e394c [C++11] Replacing ObjCInterfaceDecl iterators all_referenced_protocol_begin() and all_referenced_protocol_end() with iterator_range all_referenced_protocols(). Updating all of the usages of the iterators with range-based for loops.
llvm-svn: 203848
2014-03-13 20:55:22 +00:00
Aaron Ballman 574705ed7f [C++11] Replacing CXXRecordDecl iterators bases_begin() and bases_end() with iterator_range bases(). Updating all of the usages of the iterators with range-based for loops.
llvm-svn: 203803
2014-03-13 15:41:46 +00:00
Craig Topper e14c0f8e73 [C++11] Add 'override' keyword to virtual methods that override their base class.
llvm-svn: 203640
2014-03-12 04:55:44 +00:00
Ahmed Charles b89843299a Replace OwningPtr with std::unique_ptr.
This compiles cleanly with lldb/lld/clang-tools-extra/llvm.

llvm-svn: 203279
2014-03-07 20:03:18 +00:00
Aaron Ballman 63ab760ebe [C++11] Updating getUsingDirectives to use iterator_range instead of a std::pair.
llvm-svn: 203239
2014-03-07 13:44:44 +00:00
Aaron Ballman 86c9390673 [C++11] Replacing iterators redecls_begin() and redecls_end() with iterator_range redecls(). Updating all of the usages of the iterators with range-based for loops, which allows the begin/end forms to be removed entirely.
llvm-svn: 203179
2014-03-06 23:45:36 +00:00
Benjamin Kramer 867ea1d426 [C++11] Replace llvm::tie with std::tie.
llvm-svn: 202639
2014-03-02 13:01:17 +00:00
Benjamin Kramer 167e999be9 [C++11] Replace llvm::next and llvm::prior with std::next and std::prev.
llvm-svn: 202635
2014-03-02 12:20:24 +00:00
Kaelyn Uhrain b4b1475322 Don't suggest non-static methods as corrections when they obviously
won't work (i.e. when not doing a member lookup and not in a method from
the same class or a descendant class).

llvm-svn: 202520
2014-02-28 18:12:42 +00:00
Kaelyn Uhrain 0e35355c04 PR18685: Ignore class template specializations as potential
nested-name-specifiers for typos unless the typo already has
a nested-name-specifier that is a template specialization.

llvm-svn: 201056
2014-02-09 21:47:04 +00:00
Kaelyn Uhrain 21a6617c34 Don't consider records with a NULL identifier as a name for typo correction.
Because in C++, "anonymous" doesn't mean "nameless" for records. In
other words, RecordDecl::isAnonymousStructOrUnion only returns true if
the record lacks a name *and* is not used as the type in an object's
declaration.

llvm-svn: 200868
2014-02-05 18:57:51 +00:00
Richard Smith bdd146435f Add implicit declarations of allocation functions when looking them up for
redeclaration, not just when looking them up for a use -- we need the implicit
declaration to appropriately check various properties of them (notably, whether
they're deleted).

llvm-svn: 200729
2014-02-04 01:14:30 +00:00
Alp Toker 314cc81b8c Rename getResultType() on function and method declarations to getReturnType()
A return type is the declared or deduced part of the function type specified in
the declaration.

A result type is the (potentially adjusted) type of the value of an expression
that calls the function.

Rule of thumb:

  * Declarations have return types and parameters.
  * Expressions have result types and arguments.

llvm-svn: 200082
2014-01-25 16:55:45 +00:00
Richard Smith 8c7bd6ac1a Don't forget about a builtin if we're about to redeclare it and we couldn't
create an implicit declaration of it (because some type it depends on is
unavailable). This had the effect of causing us to not implicitly give it the
right attributes. It turns out that glibc's __sigsetjmp is declared before
sigjmp_buf is declared, and this resulted in us not implicitly giving it
__attribute__((returns_twice)), which in turn resulted in miscompiles in any C
code calling glibc's sigsetjmp.

(See also the vaguely-related sourceware.org/PR4662.)

llvm-svn: 199850
2014-01-22 23:07:19 +00:00
Alp Toker a2794f9f36 Introduce and use Decl::getAsFunction() to simplify templated function checks
Lift the getFunctionDecl() utility out of the parser into a general
Decl::getAsFunction() and use it to simplify other parts of the implementation.

Reduce isFunctionOrFunctionTemplate() to a simple type check that works the
same was as the other is* functions and move unwrapping of shadowed decls to
callers so it doesn't get run twice.

Shuffle around canSkipFunctionBody() to reduce virtual dispatch on ASTConsumer.
There's no need to query when we already know the body can't be skipped.

llvm-svn: 199794
2014-01-22 07:29:52 +00:00
Alp Toker 9cacbabd33 Rename FunctionProtoType accessors from 'arguments' to 'parameters'
Fix a perennial source of confusion in the clang type system: Declarations and
function prototypes have parameters to which arguments are supplied, so calling
these 'arguments' was a stretch even in C mode, let alone C++ where default
arguments, templates and overloading make the distinction important to get
right.

Readability win across the board, especially in the casting, ADL and
overloading implementations which make a lot more sense at a glance now.

Will keep an eye on the builders and update dependent projects shortly.

No functional change.

llvm-svn: 199686
2014-01-20 20:26:09 +00:00
Alp Toker bfa3934f27 Rename language option MicrosoftMode to MSVCCompat
There's been long-standing confusion over the role of these two options. This
commit makes the necessary changes to differentiate them clearly, following up
from r198936.

MicrosoftExt (aka. fms-extensions):
 Enable largely unobjectionable Microsoft language extensions to ease
 portability. This mode, also supported by gcc, is used for building software
 like FreeBSD and Linux kernel extensions that share code with Windows drivers.

MSVCCompat (aka. -fms-compatibility, formerly MicrosoftMode):
 Turn on a special mode supporting 'heinous' extensions for drop-in
 compatibility with the Microsoft Visual C++ product. Standards-compilant C and
 C++ code isn't guaranteed to work in this mode. Implies MicrosoftExt.

Note that full -fms-compatibility mode is currently enabled by default on the
Windows target, which may need tuning to serve as a reasonable default.

See cfe-commits for the full discourse, thread 'r198497 - Move MS predefined
type_info out of InitializePredefinedMacros'

No change in behaviour.

llvm-svn: 199209
2014-01-14 12:51:41 +00:00
Nick Lewycky 5641233047 Use the appropriate SourceLocation for the template backtrace when doing
template argument deduction.

llvm-svn: 198995
2014-01-11 02:37:12 +00:00
Alp Toker c108676822 Eliminate the last trivial NDEBUG uses in clang headers
assert(sanity()) reads so much better than preprocessor conditional blocks.

llvm-svn: 196657
2013-12-07 13:51:35 +00:00
Benjamin Kramer fc58b043b7 Sema: Make helper function static.
llvm-svn: 193857
2013-11-01 11:50:55 +00:00
Richard Smith 3876cc88ac PR17731: When determining whether a tag and a non-tag were declared in the same
scope, be careful about function-scope declarations (which are not declared in
their semantic context).

llvm-svn: 193671
2013-10-30 01:02:04 +00:00
Kaelyn Uhrain 8aa8da85ca Allow CorrectTypo to replace CXXScopeSpecifiers that refer to classes.
Now that CorrectTypo knows how to correctly search classes for typo
correction candidates, there is no good reason to only replace an
existing CXXScopeSpecifier if it refers to a namespace. While the actual
enablement was a matter of changing a single comparison, the fallout
from enabling the functionality required a lot more code changes
(including my two previous commits).

llvm-svn: 193020
2013-10-19 00:05:00 +00:00
Kaelyn Uhrain f7b63e3e18 Be smarter about deciding to add a leading '::' to a
NestedNameSpecifier that replaces an existing specifier.

llvm-svn: 193019
2013-10-19 00:04:52 +00:00
Kaelyn Uhrain 5315a4631b Merge NamespaceSpecifierSet's AddNamespace and AddRecord as they are
essentially the same.

llvm-svn: 193018
2013-10-19 00:04:49 +00:00
Richard Smith 9a00bbfa4c PR17592: Ensure we diagnose shadowing a template parameter with a local extern
declaration.

llvm-svn: 192846
2013-10-16 21:12:00 +00:00
Serge Pavlov e8ae13f79c Fixed code style of my change.
llvm-svn: 192708
2013-10-15 14:24:32 +00:00
Serge Pavlov c0cd80fb20 Do not use typo correction that is unaccessible.
This patch fixes PR17019. When doing typo correction, Sema::CorrectTypo uses
correction already seen for the same typo. This causes problems if that
correction is from another scope and cannot be accessed in the current.

llvm-svn: 192594
2013-10-14 14:05:48 +00:00
Ted Kremenek c37877d7a4 Convert anachronistic use of 'void *' to 'DeclContext *' in Scope that was a holdover from the long-dead Action interface.
llvm-svn: 192203
2013-10-08 17:08:03 +00:00
Richard Smith b8b41d3ea4 Add support for WG21 N3599 (literal operator template for strings) as a GNU
extension. The GCC folks have decided to support this even though the standard
committee have not yet approved this feature.

Patch by Hristo Venev!

llvm-svn: 192128
2013-10-07 19:57:58 +00:00
Aaron Ballman 7fc6e1bc59 Silencing an MSVC warning; SmallSet::count returns a bool instead of a size_t.
llvm-svn: 192043
2013-10-05 19:56:07 +00:00
Kaelyn Uhrain 653ff2431b Speed up CorrectTypo by avoiding lookups on unreasonable candidates.
llvm-svn: 191846
2013-10-02 18:26:35 +00:00
Eli Friedman 3be1a1c0b5 Fix typo correction usage of SemaAccess.cpp.
When we check access for lookup results, make sure we propagate the
result's access to the access control APIs; this can be different from
the natural access of the declaration depending on the path used by the lookup.

PR17394.

llvm-svn: 191726
2013-10-01 02:44:48 +00:00
Kaelyn Uhrain 0e23844f57 Cache the location of failed typo corrections so that typo correction
isn't repeatedly attempted for the same identifier at the same location.

llvm-svn: 191543
2013-09-27 19:40:08 +00:00
Kaelyn Uhrain 95995be7a3 Teach typo correction to look inside of classes like it does namespaces.
Unlike with namespaces, searching inside of classes requires also
checking the access to correction candidates (i.e. don't suggest a
correction to a private class member for a correction occurring outside
that class and its methods or friends).

Included is a small (one line) fix for a bug, that was uncovered while
cleaning up the unit tests, where the decls from a TypoCorrection candidate
were preserved in new TypoCorrection candidates that are derived (copied)
from the old TypoCorrection--notably when creating a new candidate by
changing the NestedNameSpecifier associated with the base idenitifer.

llvm-svn: 191449
2013-09-26 19:10:29 +00:00
Richard Smith 541b38be7b Switch the semantic DeclContext for a block-scope declaration of a function or
variable from being the function to being the enclosing namespace scope (in
C++) or the TU (in C). This allows us to fix a selection of related issues
where we would build incorrect redeclaration chains for such declarations, and
fail to notice type mismatches.

Such declarations are put into a new IdentifierNamespace, IDNS_LocalExtern,
which is only found when searching scopes, and not found when searching
DeclContexts. Such a declaration is only made visible in its DeclContext if
there are no non-LocalExtern declarations.

llvm-svn: 191064
2013-09-20 01:15:31 +00:00
Richard Smith 1fff95c702 PR13657 (and duplicates):
When a comma occurs in a default argument or default initializer within a
class, disambiguate whether it is part of the initializer or whether it ends
the initializer.

The way this works (which I will be proposing for standardization) is to treat
the comma as ending the default argument or default initializer if the
following token sequence matches the syntactic constraints of a
parameter-declaration-clause or init-declarator-list (respectively).

This is both consistent with the disambiguation rules elsewhere (where entities
are treated as declarations if they can be), and should have no regressions
over our old behavior. I think it might also disambiguate all cases correctly,
but I don't have a proof of that.

There is an annoyance here: because we're performing a tentative parse in a
situation where we may not have seen declarations of all relevant entities (if
the comma is part of the initializer, lookup may find entites declared later in
the class), we need to turn off typo-correction and diagnostics during the
tentative parse, and in the rare case that we decide the comma is part of the
initializer, we need to revert all token annotations we performed while
disambiguating.

Any diagnostics that occur outside of the immediate context of the tentative
parse (for instance, if we trigger the implicit instantiation of a class
template) are *not* suppressed, mirroring the usual rules for a SFINAE context.

llvm-svn: 190639
2013-09-12 23:28:08 +00:00
Richard Smith d55889a655 C++ modules: if a class is defined in multiple modules (for instance, because
it is an implicit instantiation of a class template specialization), pick the
first-loaded definition to be the canonical definition, and merge all other
definitions into it.

This is still rather incomplete -- we need to extend every form of declaration
that can appear within a CXXRecordDecl to be redeclarable if it came from an
AST file (this includes fields, enumerators, ...).

llvm-svn: 190315
2013-09-09 16:55:27 +00:00
Serge Pavlov 0ccd3f61b1 Removed useless default branch of switch statement.
The problem was caught by sanitizer build.

llvm-svn: 189575
2013-08-29 08:20:07 +00:00
Serge Pavlov 9929209dfb Change return type of Sema::DiagnoseAmbiguousLookup from bool to void.
The function always returned true value, which was never used.

llvm-svn: 189571
2013-08-29 07:23:24 +00:00
Reid Kleckner 78af0708b7 Delete CC_Default and use the target default CC everywhere
Summary:
Makes functions with implicit calling convention compatible with
function types with a matching explicit calling convention.  This fixes
things like calls to qsort(), which has an explicit __cdecl attribute on
the comparator in Windows headers.

Clang will now infer the calling convention from the declarator.  There
are two cases when the CC must be adjusted during redeclaration:
1. When defining a non-inline static method.
2. When redeclaring a function with an implicit or mismatched
convention.

Fixes PR13457, and allows clang to compile CommandLine.cpp for the
Microsoft C++ ABI.

Excellent test cases provided by Alexander Zinenko!

Reviewers: rsmith

Differential Revision: http://llvm-reviews.chandlerc.com/D1231

llvm-svn: 189412
2013-08-27 23:08:25 +00:00
Robert Wilhelm 25284cc95b Use pop_back_val() instead of both back() and pop_back().
No functionality change intended.

llvm-svn: 189112
2013-08-23 16:11:15 +00:00
Richard Smith e156254d4c During typo correction, check for an exact match in an unimported module. If we
find one, then report the error as a missing import instead of as a typo.

llvm-svn: 188821
2013-08-20 20:35:18 +00:00
Chandler Carruth 7deaae76ec Fix a use-after-free found in libclang when doing code completion. The
loop processing the candidates can cause new declerations to be added to
the context, invalidating lookup_result. To avoid that, make a copy of
the list of declarations to iterate over.

I don't have a way to check in a test case for this as it involves
a giant pile of source code and a generated PCH file used to accelerate
code completion, all of this running under ASan.

llvm-svn: 188623
2013-08-18 07:20:52 +00:00
Richard Smith f9b1510576 Refactor all diagnosing of TypoCorrections through a common function, in
preparation for teaching this function how to diagnose a correction that
includes importing a module.

llvm-svn: 188602
2013-08-17 00:46:16 +00:00
Richard Smith 1c34fb78e7 Fix implementation of C11 6.2.7/4 and C++11 [dcl.array]p3:
When a local extern declaration redeclares some other entity, the type of that
entity is merged with the prior type if the prior declaration is visible (in C)
or is declared in the same scope (in C++).

 - Make LookupRedeclarationWithLinkage actually work in C++, use it in the right
   set of cases, and make it track whether it found a shadowed declaration.
 - Track whether we found a declaration in the same scope (for C++) including
   across serialization and template instantiation.

llvm-svn: 188307
2013-08-13 18:18:50 +00:00
Kaelyn Uhrain f0aabdadc6 Add hooks for typo correction to ExternalSemaSource, courtesy of Luke Zarko.
llvm-svn: 188196
2013-08-12 19:54:38 +00:00
Robert Wilhelm 16e94b91ef Omit llvm:: before ArrayRef, as we have using llvm::ArrayRef in include/clang/Basic/LLVM.h.
llvm-svn: 188089
2013-08-09 18:02:13 +00:00
Richard Smith 114394f824 Implement [class.friend]p11's special name lookup rules for friend declarations
of local classes. We were previously handling this by performing qualified
lookup within a function declaration(!!); replace it with the proper scope
lookup.

llvm-svn: 188050
2013-08-09 04:35:01 +00:00
Richard Smith 0e5d7b8c6b When we perform dependent name lookup during template instantiation, it's not
sufficient to only consider names visible at the point of instantiation,
because that may not include names that were visible when the template was
defined. More generally, if the instantiation backtrace goes through a module
M, then every declaration visible within M should be available to the
instantiation. Any of those declarations might be part of the interface that M
intended to export to a template that it instantiates.

The fix here has two parts:

1) If we find a non-visible declaration during name lookup during template
instantiation, check whether the declaration was visible from the defining
module of all entities on the active template instantiation stack. The defining
module is not the owning module in all cases: we look at the module in which a
template was defined, not the module in which it was first instantiated.

2) Perform pending instantiations at the end of a module, not at the end of the
translation unit. This is general goodness, since it significantly cuts down
the amount of redundant work that is performed in every TU importing a module,
and also implicitly adds the module containing the point of instantiation to
the set of modules checked for declarations in a lookup within a template
instantiation.

There's a known issue here with template instantiations performed while
building a module, if additional imports are added later on. I'll fix that
in a subsequent commit.

llvm-svn: 187167
2013-07-25 23:08:39 +00:00
Richard Smith 6401768ac4 Reinstate r186040, with additional fixes and more test coverage (reverted in
r186331).

Original commit log:
  If we friend a declaration twice, that should not make it visible to
  name lookup in the surrounding context. Slightly rework how we handle
  friend declarations to inherit the visibility of the prior
  declaration, rather than setting a friend declaration to be visible
  whenever there was a prior declaration.

llvm-svn: 186546
2013-07-17 23:53:16 +00:00
Chandler Carruth 9324d169bd Re-revert r86040, which was un-reverted in r186199.
This breaks the build of basic patterns with repeated friend
declarations. See the added test case in SemaCXX/friend.cpp or the test
case reported to the original commit log.

Original commit log:
  If we friend a declaration twice, that should not make it visible to
  name lookup in the surrounding context. Slightly rework how we handle
  friend declarations to inherit the visibility of the prior
  declaration, rather than setting a friend declaration to be visible
  whenever there was a prior declaration.

llvm-svn: 186331
2013-07-15 17:27:42 +00:00
Craig Topper d6d31aceea Add 'static' and 'const' qualifiers to some arrays of strings.
llvm-svn: 186314
2013-07-15 08:24:27 +00:00
Craig Topper e5ce831c7c Use llvm::array_lengthof to replace sizeof(array)/sizeof(array[0]).
llvm-svn: 186300
2013-07-15 03:38:40 +00:00
Richard Smith 141942fcca Unrevert r186040, reverted in r186185, with fix for PR16597.
Original commit log:
  If we friend a declaration twice, that should not make it visible to
  name lookup in the surrounding context. Slightly rework how we handle
  friend declarations to inherit the visibility of the prior
  declaration, rather than setting a friend declaration to be visible
  whenever there was a prior declaration.

llvm-svn: 186199
2013-07-12 20:38:49 +00:00
Chandler Carruth 9bdd1bb403 Revert r186040 to fix PR16597 while Richard investigates what the best
fix is.

Original commit log:
  If we friend a declaration twice, that should not make it visible to
  name lookup in the surrounding context. Slightly rework how we handle
  friend declarations to inherit the visibility of the prior
  declaration, rather than setting a friend declaration to be visible
  whenever there was a prior declaration.

llvm-svn: 186185
2013-07-12 18:54:40 +00:00
Richard Smith 7a73449b31 If we friend a declaration twice, that should not make it visible to name
lookup in the surrounding context. Slightly rework how we handle friend
declarations to inherit the visibility of the prior declaration, rather
than setting a friend declaration to be visible whenever there was a prior
declaration.

llvm-svn: 186040
2013-07-10 22:04:13 +00:00
Kaelyn Uhrain 53e721980b Make a couple of useful typo correction callbacks more widely available.
llvm-svn: 185880
2013-07-08 23:13:39 +00:00
Craig Topper 2341c0d3b2 Use SmallVectorImpl instead of SmallVector for iterators and references to avoid specifying the vector size unnecessarily.
llvm-svn: 185610
2013-07-04 03:08:24 +00:00
Kaelyn Uhrain 10413a46a0 Allow typo correction to try removing nested name specifiers.
The removal is tried by retrying the failed lookup of a correction
candidate with either the MemberContext or SS (CXXScopeSpecifier) or
both set to NULL if they weren't already. If the candidate identifier
is then looked up successfully, make a note in the candidate that the
SourceRange should include any existing nested name specifier even if
the candidate isn't adding a different one (i.e. the candidate has a
NULL NestedNameSpecifier).

Also tweak the diagnostic messages to differentiate between a suggestion
that just replaces the identifer but leaves the existing nested name
specifier intact and one that replaces the entire qualified identifier,
in cases where the suggested replacement is unqualified.

llvm-svn: 185487
2013-07-02 23:47:44 +00:00
Kaelyn Uhrain b18b0c0f16 Look for corrections in enclosing namespaces that require a global NestedNameSpecifier.
CorrectTypo will now see and consider those corrections that are effectively
shadowed by other declarations in a closer context when resolved via an
unqualified lookup. This involves adding any parent namespaces to the set of
namespaces as fully-qualified name specifiers, and also adding potential
corrections that passed name lookup but were rejected by the given
CorrectionCandidateCallback into the set of failed corrections that should be
tried with the set of namespace specifiers.

llvm-svn: 185486
2013-07-02 23:47:35 +00:00
Kaelyn Uhrain 52dd02d8ef Add the global namespace (the "::" namespace specifier) to the list of
namespaces to try for potential typo corrections.

llvm-svn: 184762
2013-06-24 17:49:03 +00:00
Nico Weber e1687c5e25 Lazily provide a __float128 dummy type in -std=gnu++11 mode.
This is needed to parse libstdc++ 4.7's type_traits, see PR13530.

llvm-svn: 184476
2013-06-20 21:44:55 +00:00
David Blaikie d4da8728ba Provide operator<< for stream output of DeclarationNames
ASTDumper was already trying to do this & instead got an implicit bool
conversion by surprise (thus printing out 0 or 1 instead of the name of
the declaration). To avoid that issue & simplify call sites, simply make
it the normal/expected operator<<(raw_ostream&, ...) overload & simplify
all the existing call sites. (bonus: this function doesn't need to be a
member or friend, it's just using public API in DeclarationName)

llvm-svn: 181832
2013-05-14 21:04:00 +00:00
Dmitri Gribenko 44ebbd5436 Replace ArrayRef<T>() with None, now that we have an implicit ArrayRef constructor from None
Patch by Robert Wilhelm.

llvm-svn: 181139
2013-05-05 00:41:58 +00:00
Argyrios Kyrtzidis 56c56d218d Revert r177218.
Per discussion in cfe-commits, asserting may be a better way than introducing a special test flag.

llvm-svn: 181073
2013-05-03 23:20:27 +00:00
Richard Smith 27d807cc9c Don't treat a non-deduced 'auto' type as being type-dependent. Instead, there
are now two distinct canonical 'AutoType's: one is the undeduced 'auto'
placeholder type, and the other is a deduced-but-dependent type. All
deduced-to-a-non-dependent-type cases are still non-canonical.

llvm-svn: 180789
2013-04-30 13:56:41 +00:00
Douglas Gregor c197057b42 <rdar://problem/13605348> Don't consider invalid user-defined literal operators during overload resolution.
llvm-svn: 179150
2013-04-10 05:18:00 +00:00
Douglas Gregor 8ccbc18efa Skip transparent contexts when looking for using directives in name lookup.
Fixes the bootstrap regression I introduced in r179067.

llvm-svn: 179079
2013-04-09 01:49:26 +00:00
Douglas Gregor cc9406c055 <rdar://problem/13540899> Collect using directives from all of the semantic contexts not represented by scopes.
This fixes a regression I introduced in r178136, where we would not
consider the using directives from the semantic declaration contexts
that aren't represented by the lexical scopes (Scope) when performing
unqualified name lookup. This lead to horribly funny diagnostics like
"no identifier named 'foo'; did you mean 'foo'?".

llvm-svn: 179067
2013-04-08 23:11:25 +00:00
Nick Lewycky 0d9b3191f6 Fix typo in assertion.
llvm-svn: 179061
2013-04-08 21:55:21 +00:00
Douglas Gregor 151976694a <rdar://problem/13560075> Teach name lookup for builtin names to find hidden declarations.
Normal name lookup ignores any hidden declarations. When name lookup
for builtin declarations fails, we just synthesize a new
declaration at the point of use. With modules, this could lead to
multiple declarations of the same builtin, if one came from a (hidden)
submodule that was later made visible. Teach name lookup to always
find builtin names, so we don't create these redundant declarations in
the first place.

llvm-svn: 178711
2013-04-03 23:06:26 +00:00
Kaelyn Uhrain 989b7ca092 Give the default CorrectionCandidateCallback::ValidateCandidate some
smarts so that it doesn't approve of keywords and/or type names when it
knows (based on its flags) that those kinds of corrections are not
wanted.

llvm-svn: 178668
2013-04-03 16:59:49 +00:00
Douglas Gregor b0d0aa5cdc <rdar://problem/13317030> Consider using directives when performing unqualified name lookup into declarations contexts represented by the qualified-id but not in the actual scope hierarchy.
llvm-svn: 178136
2013-03-27 12:51:49 +00:00
Argyrios Kyrtzidis 3065a0fce4 Remove -Wspellcheck and replace it with a diagnostic option.
Thanks to Richard S. for pointing out that the warning would show up
with -Weverything.

llvm-svn: 177218
2013-03-16 01:40:35 +00:00
Argyrios Kyrtzidis 3e56dd4fc9 Don't try to typo-correct 'super' in an objc method.
This created 2 issues:

1) Performance issue, since typo-correction with PCH/modules is rather expensive.
2) Correctness issue, since if it managed to "correct" 'super' then bogus compiler errors would
be emitted, like this:

3.m:8:3: error: unknown type name 'super'; did you mean 'super1'?
  super.x = 0;
  ^~~~~
  super1
t3.m:5:13: note: 'super1' declared here
typedef int super1;
            ^
t3.m:8:8: error: expected identifier or '('
  super.x = 0;
       ^

llvm-svn: 177126
2013-03-14 22:56:43 +00:00
Jordan Rose 5c38272c1a ArrayRef-ize ASTContext::getFunctionType and Sema::BuildFunctionType.
No (intended) functionality change.

llvm-svn: 176726
2013-03-08 21:51:21 +00:00
Argyrios Kyrtzidis 1fcd7fd633 In LookupResult::resolveKind(), when handling multiple found declarations, ignore invalid declarations.
This reduces the "ambiguous reference" errors (which are rather strange in C/ObjC) and fixes an assertion hit
with an invalid code test case.

llvm-svn: 175869
2013-02-22 06:58:37 +00:00
Nick Lewycky 8334af8c2a Preserve Sema::UndefinedInternals across PCH boundaries. Fixes
-Wundefined-internal warnings with PCH.

llvm-svn: 173538
2013-01-26 00:35:08 +00:00
Douglas Gregor 048fbfa302 Rework the traversal of Objective-C categories and extensions to
consider (sub)module visibility.

The bulk of this change replaces myriad hand-rolled loops over the
linked list of Objective-C categories/extensions attached to an
interface declaration with loops using one of the four new category
iterator kinds:

  visible_categories_iterator: Iterates over all visible categories
  and extensions, hiding any that have their "hidden" bit set. This is
  by far the most commonly used iterator.

  known_categories_iterator: Iterates over all categories and
  extensions, ignoring the "hidden" bit. This tends to be used for
  redeclaration-like traversals.

  visible_extensions_iterator: Iterates over all visible extensions,
  hiding any that have their "hidden" bit set.

  known_extensions_iterator: Iterates over all extensions, whether
  they are visible to normal name lookup or not.

The effect of this change is that any uses of the visible_ iterators
will respect module-import visibility. See the new tests for examples.

Note that the old accessors for categories and extensions are gone;
there are *Raw() forms for some of them, for those (few) areas of the
compiler that have to manipulate the linked list of categories
directly. This is generally discouraged.

Part two of <rdar://problem/10634711>.
 

llvm-svn: 172665
2013-01-16 23:00:23 +00:00
Richard Smith 550de45861 PR14950: Fix out-of-bounds function parameter access in literal operator lookup.
llvm-svn: 172514
2013-01-15 07:12:59 +00:00
Dmitri Gribenko f857950d39 Remove useless 'llvm::' qualifier from names like StringRef and others that are
brought into 'clang' namespace by clang/Basic/LLVM.h

llvm-svn: 172323
2013-01-12 19:30:44 +00:00
Richard Smith 2bf7fdb723 s/CPlusPlus0x/CPlusPlus11/g
llvm-svn: 171367
2013-01-02 11:42:31 +00:00
David Blaikie ff7d47a354 Change DeclContextLookup(Const)Result to (Mutable)ArrayRef<NamedDecl*>, as per review discussion in r170365
This does limit these typedefs to being sequences, but no current usage
requires them to be contiguous (we could expand this to a more general
iterator pair range concept at some point).

Also, it'd be nice if SmallVector were constructible directly from an ArrayRef
but this is a bit tricky since ArrayRef depends on SmallVectorBaseImpl for the
inverse conversion. (& generalizing over all range-like things, while nice,
would require some nontrivial SFINAE I haven't thought about yet)

llvm-svn: 170482
2012-12-19 00:45:41 +00:00
Chandler Carruth 3a02247dc9 Sort all of Clang's files under 'lib', and fix up the broken headers
uncovered.

This required manually correcting all of the incorrect main-module
headers I could find, and running the new llvm/utils/sort_includes.py
script over the files.

I also manually added quite a few missing headers that were uncovered by
shuffling the order or moving headers up to be main-module-headers.

llvm-svn: 169237
2012-12-04 09:13:33 +00:00
Richard Smith 2be35f5fbb Consistently use 'needsImplicit<special member>' to determine whether we need
an implicit special member, rather than sometimes using '!hasDeclared<special
member>'. No functionality change.

llvm-svn: 169075
2012-12-01 02:35:44 +00:00
Argyrios Kyrtzidis a6567c4102 Don't return a pointer to an UnresolvedSetImpl in the CXXRecordDecl interface,
expose only the iterators instead.

llvm-svn: 168770
2012-11-28 03:56:09 +00:00
Richard Smith 7d125a11f1 Simplify checking for whether we should implicitly declare special members and
add some assertions. No functionality change.

llvm-svn: 168725
2012-11-27 21:20:31 +00:00
Kaelyn Uhrain f60b55ae49 When adding a NamedDecl to a correction, add the underlying Decl (via
getUnderlyingDecl()) so that derivatives of
CorrectionCandidateCallback::ValidateCandidate(...) don't have to worry
about being thrown by UsingDecls and such.

llvm-svn: 168317
2012-11-19 18:49:53 +00:00
Richard Smith b6626748c2 DR1442: In a range-based for statement, namespace 'std' is not an associated
namespace.

llvm-svn: 166194
2012-10-18 17:56:02 +00:00
David Blaikie 04ea41c39a Fix typo correction of one qualified name to another.
When suggesting "foo::bar" as a correction for "fob::bar" we mistakenly
replaced only "bar" with "foo::bar" producing "fob::foo::bar" which was broken.

This corrects that replacement in as many places as I could find & provides
test cases for all those cases I could find a test case for. There are a couple
that don't seem to be reachable (one looks entirely dead, the other just
doesn't seem to ever get called with a namespace to namespace change).

Review by Richard Smith ( http://llvm-reviews.chandlerc.com/D57 ).

llvm-svn: 165817
2012-10-12 20:00:44 +00:00
Eli Friedman b826a00857 Fix the AST representation for non-type template arguments to encode
enough information so we can mangle them correctly in cases involving
dependent parameter types. (This specifically impacts cases involving
null pointers and cases involving parameters of reference type.)
Fix the mangler to use this information instead of trying to scavenge
it out of the parameter declaration.

<rdar://problem/12296776>.

llvm-svn: 164656
2012-09-26 02:36:12 +00:00
Craig Topper e6706e40bb Remove Context argument from TemplateDeductionInfo constructor. It was no longer needed after the unused Context member was removed in r164104.
llvm-svn: 164196
2012-09-19 02:26:47 +00:00
Richard Smith a6a03369da Remove RequireCompleteType call which was made redundant by r162586.
llvm-svn: 162630
2012-08-24 23:51:39 +00:00
John McCall 7d8b041999 Instantiate class template specializations during ADL.
llvm-svn: 162586
2012-08-24 20:38:34 +00:00
Benjamin Kramer a2dcac1095 Fix PR13394: Erasing from a vector changes the end of the vector, so make sure we always have the right end.
llvm-svn: 160855
2012-07-27 10:21:08 +00:00
Sylvestre Ledru 830885ca64 Fix a typo (the the => the)
llvm-svn: 160622
2012-07-23 08:59:39 +00:00
Richard Smith 1c6461ef63 PR13381: consider cv-qualifiers on a class member's type when determining which
constructor will be used for moving that object, in the computation of its
exception specification.

llvm-svn: 160417
2012-07-18 03:36:00 +00:00
Jordan Rose 58d547200e Add support for the C11 _Alignof keyword.
This behaves like the existing GNU __alignof and C++11 alignof keywords;
most of the patch is simply adding the third token spelling to various places.

llvm-svn: 159494
2012-06-30 21:33:57 +00:00
James Dennett 91738ffda3 Documentation cleanup: making \param and \returns docs match the code.
llvm-svn: 158985
2012-06-22 10:32:46 +00:00
James Dennett 41725129a4 Documentation cleanup: making \param docs match the code.
llvm-svn: 158982
2012-06-22 10:16:05 +00:00
James Dennett 51a8d8b8b5 Documentation cleanup: escape "::", and other minor reformatting
llvm-svn: 158741
2012-06-19 21:05:49 +00:00
Richard Smith b3a1df03a9 PR13051: Only suggest the 'template' and 'operator' keywords when performing
typo-correction after a scope specifier.

llvm-svn: 158231
2012-06-08 21:35:42 +00:00
Kaelyn Uhrain 493ea635fe Allow CorrectTypo to add/modify nested name qualifiers to typos that
are otherwise too short to try to correct.

The TODOs added to two of the tests are for existing deficiencies in the
typo correction code that could be exposed by using longer identifiers.

llvm-svn: 158109
2012-06-06 20:54:51 +00:00
David Blaikie 40ed29730b Revert Decl's iterators back to pointer value_type rather than reference value_type
In addition, I've made the pointer and reference typedef 'void' rather than T*
just so they can't get misused. I would've omitted them entirely but
std::distance likes them to be there even if it doesn't use them.

This rolls back r155808 and r155869.

Review by Doug Gregor incorporating feedback from Chandler Carruth.

llvm-svn: 158104
2012-06-06 20:45:41 +00:00
Benjamin Kramer 474261af7b Fix typos found by http://github.com/lyda/misspell-check
llvm-svn: 157886
2012-06-02 10:20:41 +00:00
Kaelyn Uhrain ba896f17ae Don't allow multiple correction candidates that have the same identifier
but different nested name specifiers to quietly clobber each other so
only one remains if they do not refer to the same NamedDecl. Fixes
PR12951.

llvm-svn: 157823
2012-06-01 18:11:16 +00:00
Kaelyn Uhrain 34fab5598d In TypoCorrectionConsumer, BestResults to CorrectionResults to lessen
the confusion among all of the uses of Best* in relation to the set of
possible typo correction results. Also add a method to return the set of
typo corrections that have the single best edit distance--it returns the
second half of the first pair in TypoEditDistanceMap (with
getBestEditDistance already returning the first half).

llvm-svn: 157781
2012-05-31 23:32:58 +00:00
David Blaikie 2e4ae51fb4 Implement simplify_type traits for redecl_iterator.
Based on Chandler Carruth's feedback on r155869.

llvm-svn: 155929
2012-05-01 19:49:42 +00:00
David Blaikie b15de1eaed Remove ref/value inconsistency in redecl_iterator.
Similar to r155808 - this mistake has been made in a few iterators.

Based on Chandler Carruth's feedback to r155808 I added an implicit conversion
to Decl* to ease adoption/usage. Useful for the pointer comparison, but not the
dyn_cast (due to template argument deduction causing the conversion not to be
used) - there for future convenience, though. This idiom (op T* for iterators)
seems to be fairly idiomatic within the LLVM codebase & I'll likely add it as I
fix up the other iterators here.

llvm-svn: 155869
2012-05-01 00:48:43 +00:00
Richard Smith 83c478d389 Fix bug where a class's (deleted) copy constructor would be implicitly given a
non-const reference parameter type if the class had any subobjects with deleted
copy constructors. This causes a rejects-valid if the class's copy constructor
is explicitly defaulted (as happens for some implementations of std::pair etc).

llvm-svn: 155218
2012-04-20 18:46:14 +00:00
Benjamin Kramer 73faad6409 Directly store TypoResultsMaps in the TypoEditDistanceMap, getting rid of manual deletion.
llvm-svn: 154736
2012-04-14 08:26:28 +00:00
Benjamin Kramer ac9b31a404 Delete the TypoResultsMap when erasing the pointer to it.
This manual deleting is error-prone, but we can't just put an OwningPtr in a
std::map :(

llvm-svn: 154707
2012-04-13 23:09:10 +00:00
Nick Lewycky c392148414 Remove more redundant lookups. Add a new "all_lookups_iterator" which provides
a view over the contents of a DeclContext without exposing the implementation
details of the StoredDeclsMap. Use this in LookupVisibleDecls to find the
visible declarations. Fixes PR12339!

llvm-svn: 153970
2012-04-03 21:44:08 +00:00
Nick Lewycky 13668f2083 Don't treat synthesized ivars as being in the base class for the purpose of
looking up visible decls.

llvm-svn: 153967
2012-04-03 20:26:45 +00:00
Kaelyn Uhrain f4657d5bd7 Replace the workaround from r153445 with a proper fix.
Infinite recursion was happening when DiagnoseInvalidRedeclaration
called ActOnFunctionDeclarator to check if a typo correction works when
the correction was just to the nested-name-specifier because the wrong
DeclContext was being passed in. Unlike a number of functions
surrounding typo correction, the DeclContext passed in for a function is
the context of the function name after applying any nested name
specifiers, not the lexical DeclContext where the
function+nested-name-specifier appears.

llvm-svn: 153962
2012-04-03 18:20:11 +00:00
Richard Smith 852265ff1c PR10217: Provide diagnostics explaining why an implicitly-deleted special
member function is deleted.

llvm-svn: 153773
2012-03-30 20:53:28 +00:00
Douglas Gregor b11f94590c When diagnosing an invalid out-of-line redeclaration, don't permit
typo correction to introduce a nested-name-specifier; we aren't
prepared to handle it here. Fixes PR12297 / <rdar://problem/11075219>.

llvm-svn: 153445
2012-03-26 16:54:18 +00:00
Richard Smith 7d137e3b98 Support for definitions of member enumerations of class templates outside the
class template's definition, and for explicit specializations of such enum
members.

llvm-svn: 153304
2012-03-23 03:33:32 +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
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
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
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
Daniel Dunbar 9e19f13416 Sema: Don't emit a gajillion calls to sanity() -- an empty function -- in NDEBUG
builds. Sheesh.

llvm-svn: 152279
2012-03-08 01:43:06 +00:00
Ahmed Charles b24b9aa298 ArrayRef'ize various functions in the AST/Parser/Sema.
llvm-svn: 151447
2012-02-25 11:00:22 +00:00
Richard Smith e06a2c1893 Fix a regression from r151117: ADL requires that we attempt to complete any
associated classes, since it can find friend functions declared within them,
but overload resolution does not otherwise require argument types to be
complete.

llvm-svn: 151434
2012-02-25 06:24:24 +00:00
Benjamin Kramer 3adbe1ca43 Replace some DenseSets with SmallPtrSets. Apart from the "small" optimization, the current implementation is also a denser.
llvm-svn: 151257
2012-02-23 16:06:01 +00:00
Richard Smith d951a1d9c8 Initial refactoring of 'ShouldDeleteSpecialMember', in preparation for providing
decent diagnostics. Finish the work of combining all the 'ShouldDelete'
functions into one. In unifying the code, fix a minor bug where an anonymous
union with a deleted default constructor as a member of a union wasn't being
considered as making the outer union's default constructor deleted.

llvm-svn: 150862
2012-02-18 02:02:13 +00:00
Kaelyn Uhrain 618f97ca21 Silence a valgrind warning, and remove an unused var.
llvm-svn: 150629
2012-02-15 22:59:03 +00:00
Kaelyn Uhrain 5986c3e90a Improve typo correction involving nested name specifiers.
Snooping in other namespaces when the identifier being corrected is
already qualified (i.e. a valid CXXScopeSpec is passed to CorrectTypo)
and ranking synthesized namespace qualifiers relative to the existing
qualifier is now performed. Support for disambiguating the string
representation of synthesized namespace qualifers has also been added
(the change to test/Parser/cxx-using-directive.cpp is an example of an
ambiguous relative qualifier).

llvm-svn: 150622
2012-02-15 22:14:18 +00:00
Kaelyn Uhrain 0a16a8e531 Use several weighted factors to determine typo candidate viablity.
Replace the simple Levenshtein edit distance for typo correction
candidates--and the hacky way adding namespace qualifiers would affect
the edit distance--with a synthetic "edit distance" comprised of several
factors and their relative weights. This also allows the typo correction
callback object to convey more information about the viability of a
correction candidate than simply viable or not viable.

llvm-svn: 150495
2012-02-14 18:56:48 +00:00
Kaelyn Uhrain 1c75d4084d Remove the unused TypoCorrectionConsumer::MaxEditDistance.
MaxEditDistance was effectively unused as it being initialized to the max
unsigned valued but never updated. Removing it avoids conversion
headaches once the "edit distance" of a typo correction is a weighted
composite of several values instead of roughly the number of characters
changed; comparing the weighted composite value to the number of
characters in a typo would require some form of normalization to make it
comparable to the old, character-based notion of edit distance.

llvm-svn: 149953
2012-02-07 01:32:58 +00:00
Dylan Noblesmith e27789991d Basic: import OwningPtr<> into clang namespace
llvm-svn: 149798
2012-02-05 02:12:40 +00:00
Douglas Gregor cdd11d4e7e Introduce the lambda scope before determining explicit captures, which
cleans up and improves a few things:
  - We get rid of the ugly dance of computing all of the captures in
  data structures that clone those of CapturingScopeInfo, centralizing
  the logic for accessing/updating these data structures
  - We re-use the existing capture logic for 'this', which actually
  works now.

Cleaned up some diagnostic wording in minor ways as well.

llvm-svn: 149516
2012-02-01 17:04:21 +00:00
Kaelyn Uhrain 4e8942c139 Make the callback object to Sema::CorrectTypo mandatory.
llvm-svn: 149451
2012-01-31 23:49:25 +00:00
Kaelyn Uhrain cb7a0406c3 In CorrectTypo, use the cached correction as a starting point instead.
Previously, for unqualified lookups, a positive cache hit is used as the
only non-keyword correction and a negative cache hit immediately returns
an empty TypoCorrection. With the new callback objects, this behavior
causes false negatives by not accounting for the fact that callback
objects alter the set of potential/allowed corrections. The new behavior
is to seed the set of corrections with the cached correction (for
positive hits) to estabilishing a baseline edit distance. Negative cache
hits are only stored or used when either no callback object is provided
or when it returns true for a call to ValidateCandidate with an empty
TypoCorrection (i.e. when ValidateCandidate does not seem to be doing
any checking of the TypoCorrection, such as when an instance of the base
callback class is used solely to specify the set of keywords to be accepted).

llvm-svn: 148720
2012-01-23 20:18:59 +00:00
David Blaikie e4d798f078 More dead code removal (using -Wunreachable-code)
llvm-svn: 148577
2012-01-20 21:50:17 +00:00
Kaelyn Uhrain edb4acf16b Remove the now-unused CorrectTypoContext enum.
llvm-svn: 148441
2012-01-19 00:33:34 +00:00
Douglas Gregor ec9fd13c77 De-virtualize getPreviousDecl() and getMostRecentDecl() when we know
we have a redeclarable type, and only use the new virtual versions
(getPreviousDeclImpl() and getMostRecentDeclImpl()) when we don't have
that type information. This keeps us from penalizing users with strict
type information (and is the moral equivalent of a "final" method).

Plus, settle on the names getPreviousDecl() and getMostRecentDecl()
throughout.

llvm-svn: 148187
2012-01-14 16:38:05 +00:00
Douglas Gregor 81bd038623 Make sure to consider non-DeclContext scopes properly when finding
multiple name lookup results in C/Objective-C. Fixes a regression a
caused in r147533, found by Enea Zaffanella!

llvm-svn: 148154
2012-01-13 23:06:53 +00:00
Kaelyn Uhrain 8811b3904c Fix the caching in CorrectTypo so that other non-keyword identifiers
are still added if the cached correction fails validation.

Also fix a copy-and-paste error in a comment from my previous commit.
Finally, add an example of the benefit the typo correction callback adds
to TryNamespaceTypoCorrection--which happens to also tickle the above
caching problem, as the only way a non-namespace Decl would be added to
the possible corrections is if it was cached as the correction for a
previous instance of the same typo where the typo was corrected to a
non-namespace via a different code path.

llvm-svn: 147968
2012-01-11 21:17:51 +00:00
Kaelyn Uhrain 2d317edcfd Add initial callback object support to Sema::CorrectTypo.
Also includes two examples of the callback: a wrapper/replacement for
the CorrectTypoContext enum, and a conversion of the two calls to
CorrectTypo in SemaDeclCXX.cpp (one of which provides verifiable
improvement to the typo correction, as demonstrated in the added test).

llvm-svn: 147962
2012-01-11 19:37:46 +00:00
Douglas Gregor e57e752b71 Switch NamespaceDecl from its own hand-rolled redeclaration chain over
to Redeclarable<NamespaceDecl>, so that we benefit from the improveed
redeclaration deserialization and merging logic provided by
Redeclarable<T>. Otherwise, no functionality change.

As a drive-by fix, collapse the "inline" bit into the low bit of the
original namespace/anonymous namespace, saving 8 bytes per
NamespaceDecl on x86_64.

llvm-svn: 147729
2012-01-07 09:11:48 +00:00
Douglas Gregor 5407920f82 During name lookup, use redecl_iterator to walk over the redeclaration
chain to determine whether any declaration of the given entity is
visible, eliminating the redundant (and less efficient)
getPreviousDeclaration() implementation.

This tweak uncovered an omission in the handling of
RedeclarableTemplateDecl, where we weren't making sure to search for
additional redeclarations of a template in other module files. Things
would be cleaner if RedeclarableTemplateDecl actually used Redeclarable.

llvm-svn: 147687
2012-01-06 22:05:37 +00:00
Douglas Gregor 5c193c7ed6 When we're performing name lookup for a tag, we still allow ourselves
to see hidden declarations because every tag lookup is effectively a
redeclaration lookup. For example, image that

  struct foo;

is declared in a submodule that is known but hasn't been imported. If
someone later writes

  struct foo *foo_p;

then "struct foo" is either a reference or a redeclaration. To keep
the redeclaration chains sound, we treat it like a redeclaration for
name-lookup purposes.

llvm-svn: 147588
2012-01-05 01:11:47 +00:00
Douglas Gregor 9b7b39116e Implement declaration merging for typedefs loaded from disjoint
modules, so long as the typedefs refer to the same underlying
type. This ensures that the typedefs end up in the same redeclaration
chain.

To test this, fix name lookup for C/Objective-C to properly deal with
multiple declarations with the same name in the same scope.

llvm-svn: 147533
2012-01-04 16:44:10 +00:00
Douglas Gregor 6aeecf1791 Minor tweak to name lookup for C/Objective-C: after the first name, still consider whether this is a redeclaration lookup when determining whether to look for the visible declaration
llvm-svn: 147499
2012-01-03 23:34:23 +00:00
Douglas Gregor b59643baf6 Test "merging" of typedef types across distinct modules. At present,
the AST reader doesn't actually perform a merge, because name lookup
knows how to merge identical typedefs together.

As part of this, teach C/Objective-C name lookup to return multiple
results in all cases, rather than first digging through the attributes
to see if the value is overloadable. This way, we'll catch ambiguous
lookups in C/Objective-C.

llvm-svn: 147498
2012-01-03 23:26:26 +00:00
Douglas Gregor f610267581 Eliminate ObjCForwardProtocolDecl, which is redundant now that
ObjCProtocolDecl modules forward declarations properly.

llvm-svn: 147415
2012-01-01 21:23:57 +00:00
Douglas Gregor 32c1757730 Wire up redeclaration chains for Objective-C protocols, so that both
forward declarations and definitions of an Objective-C protocol are
represented within a single chain of ObjCProtocolDecls.

llvm-svn: 147412
2012-01-01 20:30:41 +00:00
Douglas Gregor a715bfff98 Introduce the core infrastructure needed to model redeclaration chains
for Objective-C protocols, including:
  - Using the first declaration as the canonical declaration
  - Using the definition as the primary DeclContext
  - Making sure that all declarations have a pointer to the definition
  data, and that we know which declaration is the definition
  - Serialization support for redeclaration chains and for adding
  definitions to already-serialized declarations.

However, note that we're not taking advantage of much of this code
yet, because we're still re-using ObjCProtocolDecls.

llvm-svn: 147410
2012-01-01 19:51:50 +00:00
Douglas Gregor deafd0b2a4 Eliminate ObjCClassDecl, which is redundant now that ObjCInterfaceDecl
covers both declarations (@class) and definitions (@interface) of an
Objective-C class.

llvm-svn: 147299
2011-12-27 22:43:10 +00:00
Douglas Gregor 21823bfe31 When performing name lookup for a redeclaration, ignore module
visibility restrictions. This ensures that all declarations of the
same entity end up in the same redeclaration chain, even if some of
those declarations aren't visible. While this may seem unfortunate to
some---why can't two C modules have different functions named
'f'?---it's an acknowedgment that a module does not introduce a new
"namespace" of names.

As part of this, stop merging the 'module-private' bit from previous
declarations to later declarations, because we want each declaration
in a module to stand on its own because this can effect, for example,
submodule visibility.

Note that this notion of names that are invisible to normal name
lookup but are available for redeclaration lookups is how we should
implement friend declarations and extern declarations within local
function scopes. I'm not tackling that problem now.

llvm-svn: 146980
2011-12-20 18:11:52 +00:00
Douglas Gregor 05f10357a9 Completely re-implement (de-)serialization of declaration
chains. The previous implementation relied heavily on the declaration
chain being stored as a (circular) linked list on disk, as it is in
memory. However, when deserializing from multiple modules, the
different chains could get mixed up, leading to broken declaration chains.

The new solution keeps track of the first and last declarations in the
chain for each module file. When we load a declaration, we search all
of the module files for redeclarations of that declaration, then
splice together all of the lists into a coherent whole (along with any
redeclarations that were actually parsed). 

As a drive-by fix, (de-)serialize the redeclaration chains of
TypedefNameDecls, which had somehow gotten missed previously. Add a
test of this serialization.

This new scheme creates a redeclaration table that is fairly large in
the PCH file (on the order of 400k for Cocoa.h's 12MB PCH file). The
table is mmap'd in and searched via a binary search, but it's still
quite large. A future tweak will eliminate entries for declarations
that have no redeclarations anywhere, and should
drastically reduce the size of this table.

llvm-svn: 146841
2011-12-17 23:38:30 +00:00
Douglas Gregor 95ab186240 When name lookup finds a module-private Objective-C class declaration,
check whether any previous declarations of the class were visible.

llvm-svn: 146680
2011-12-15 20:36:27 +00:00
Douglas Gregor 4a814568b2 When name lookup comes across a declaration that is in a module that
is not visible, look for any previous declarations of that entity that
might be visible.

llvm-svn: 146563
2011-12-14 16:03:29 +00:00
Francois Pichet 9c39113fdb In Microsoft mode, don't perform typo correction in a template member function dependent context because it interferes with the "lookup into dependent bases of class templates" feature.
Basically typo correction will try to offer a correction instead of looking into type dependent base classes.

I found this problem while parsing Microsoft ATL code with clang.

llvm-svn: 145772
2011-12-03 15:55:29 +00:00
Douglas Gregor 2a5d14898a Make sure that name lookup in C checks whether a name is hidden.
llvm-svn: 145700
2011-12-02 20:08:44 +00:00
Douglas Gregor 89ab56d5fb When we perform a lookup for a dependent name that is a member of an
unknown specialization, treat this the same way as if the name were
not found in the current instantiation. No actual functionality
change, since apparently nothing depends on this.

llvm-svn: 142862
2011-10-24 22:24:50 +00:00
John McCall f937c023bf Rename TagDecl::isDefinition -> isCompleteDefinition
for better self-documenting code, since the semantics
are subtly different from getDefinition().

llvm-svn: 141355
2011-10-07 06:10:15 +00:00