Commit Graph

14 Commits

Author SHA1 Message Date
Richard Smith 830dfeb50d Fix handling of initialization from parenthesized initializer list.
This change fixes a crash on initialization of a reference from ({}) during
template instantiation and incidentally improves diagnostics.

This reverts a prior attempt to handle this in r286721. Instead, we teach the
initialization code that initialization cannot be performed if a source type
is required and the initializer is an initializer list (which is not an
expression and does not have a type), and likewise for function-style cast
expressions.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@298676 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-24 01:14:25 +00:00
Serge Pavlov 937ed2d04c Use descriptive message if list initializer is incorrectly parenthesized.
If initializer contains parentheses around braced list where it is not allowed,
as in construct int({0}), clang issued message like `functional-style cast
from 'void' to 'int' is not allowed`, which does not help much. Both gcc and
msvc issue message `list-initializer for non-class type must not be
parenthesized`, which is more descriptive. This change implements similar
message for clang.

Differential Revision: https://reviews.llvm.org/D25816


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@286721 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-12 15:38:55 +00:00
David Majnemer 1dc7490ad5 [Sema] Do not permit binding a reference to a compound literal
We could probably make this work if we cared enough.  However, we are
far outside any language rules at this point.

This fixes PR21834.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@235818 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-26 07:35:03 +00:00
Richard Smith 538100ae94 Improve the "braces around scalar init" warning to determine whether to warn
based on whether "redundant" braces are ever reasonable as part of the
initialization of the entity, rather than whether the initialization is
"top-level". In passing, add a warning flag for it.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@228896 91177308-0d34-0410-b5e6-96231b3b80d8
2015-02-12 01:50:05 +00:00
Larisse Voufo 619b4a3e65 Implement the remaining portion of DR1467 from r227022. I may have overlooked a few things, but this implementation comes straight from the DR resolution itself.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@227224 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-27 18:47:05 +00:00
Richard Smith 68ecda23a5 PR20844: If we fail to list-initialize a reference, map to the referenced type
before retrying the initialization to produce diagnostics. Otherwise, we may
fail to produce any diagnostics, and silently produce invalid AST in a -Asserts
build. Also add a note to this codepath to make it more clear why we were
trying to create a temporary.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@217197 91177308-0d34-0410-b5e6-96231b3b80d8
2014-09-04 22:13:39 +00:00
Richard Smith a41c97a5d1 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.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191064 91177308-0d34-0410-b5e6-96231b3b80d8
2013-09-20 01:15:31 +00:00
Richard Smith 6242a45ca5 Fix handling of braced-init-list as reference initializer within aggregate
initialization. Previously we would incorrectly require an extra set of braces
around such initializers.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182983 91177308-0d34-0410-b5e6-96231b3b80d8
2013-05-31 02:56:17 +00:00
Richard Smith 02d65ee373 Don't crash when binding a reference to a temporary pointer created from
resolving an overloaded function reference within an initializer list.
Previously we would try to resolve the overloaded function reference without
first stripping off the InitListExpr wrapper.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172517 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-15 07:58:29 +00:00
Richard Smith 6e4a0af697 PR12660: Don't crash when initializing a const reference from a braced init list
which creates a temporary by calling a constructor.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@155608 91177308-0d34-0410-b5e6-96231b3b80d8
2012-04-26 03:16:45 +00:00
Sebastian Redl cbf82092cd Be smarter in discovering list-initialization of temporaries. Fixes PR12182.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152231 91177308-0d34-0410-b5e6-96231b3b80d8
2012-03-07 16:10:45 +00:00
Sebastian Redl 3a45c0e61d Change the way we store initialization kinds so that all direct inits can distinguish between list and parens form. This allows us to correctly diagnose the last test cases from litb.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150343 91177308-0d34-0410-b5e6-96231b3b80d8
2012-02-12 16:37:36 +00:00
Sebastian Redl 1cdb70b207 Implement overload resolution for reference-typed parameters supplied with initializer lists.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145769 91177308-0d34-0410-b5e6-96231b3b80d8
2011-12-03 14:54:30 +00:00
Sebastian Redl 13dc8f98f6 Reference initialization with initializer lists.
This supports single-element initializer lists for references according to DR1288, as well as creating temporaries and binding to them for other initializer lists.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145186 91177308-0d34-0410-b5e6-96231b3b80d8
2011-11-27 16:50:07 +00:00