Commit Graph

1915 Commits

Author SHA1 Message Date
Zhihao Yuan 2c5471ddc7 [C++17] Fix class template argument deduction for default constructors without an initializer
Summary:
As the title says, this makes following code compile:

```
template<typename> struct Foo {};
Foo() -> Foo<void>;

Foo f; // ok
```

Thanks Nicolas Lesser for coining the fix.

Reviewers: rsmith, lichray

Reviewed By: rsmith, lichray

Subscribers: lichray, cfe-commits

Tags: #clang

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

llvm-svn: 328409
2018-03-24 04:32:11 +00:00
Zhihao Yuan 52b5bf8ba9 [C++17] Allow an empty expression in an if init statement
Summary:
This fixes [PR35381](https://llvm.org/pr35381) and an additional bug where clang didn't warn about the C++17 extension when having an expression in the init statement.

Thanks Nicolas Lesser for contributing the patch.

Reviewers: rsmith

Reviewed By: rsmith

Subscribers: erik.pilkington, cfe-commits

Tags: #clang

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

llvm-svn: 327782
2018-03-17 21:42:10 +00:00
Aaron Ballman 33e90d160b Implement DR2229, which prohibits unnamed bit-fields from having qualifiers in C++.
llvm-svn: 327781
2018-03-17 21:08:40 +00:00
Richard Smith c660c8f5d2 Implement C++ DR727, which permits explicit specializations at class scope.
More generally, this permits a template to be specialized in any scope in which
it could be defined, so this also supersedes DR44 and DR374 (the latter of
which we previously only implemented in C++11 mode onwards due to unclarity as
to whether it was a DR).

llvm-svn: 327705
2018-03-16 13:36:56 +00:00
Richard Smith 5d3310208a When substituting previously-checked template arguments into a template
template parameter that is an expanded parameter pack, only substitute into the
current slice, not the entire pack.

This reduces the checking of N template template arguments for an expanded
parameter pack containing N parameters from quadratic time to linear time in
the length of the pack. This is important because one (and possibly the only?)
general technique for splitting a template parameter pack in linear time
depends on doing this.

llvm-svn: 326973
2018-03-08 01:07:33 +00:00
Mikhail Maltsev 2373516cad [Sema] Improve test coverage of narrowing conversion diagnostics
Summary:
This patch adds tests of narrowing conversion diagnostics for the
'unscoped enum -> integer' case.

Reviewers: faisalv, rsmith, rogfer01

Reviewed By: rogfer01

Subscribers: cfe-commits, rogfer01

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

llvm-svn: 326551
2018-03-02 10:03:02 +00:00
Richard Smith 77a9c60aa6 Fix a couple of cases where we would fail to correctly parse deduced class template specialization types.
Specifically, we would not properly parse these types within template arguments
(for non-type template parameters), and in tentative parses. Fixing both of
these essentially requires that we parse deduced template specialization types
as types in all contexts, even in template argument lists -- in particular,
tentative parsing may look ahead and annotate a deduced template specialization
type before we figure out that we're actually supposed to treat the tokens as a
template-name. We deal with this by simply permitting deduced template
specialization types when parsing template arguments, and converting them to
template template arguments.

llvm-svn: 326299
2018-02-28 03:02:23 +00:00
Rafael Espindola 922f2aa9b2 Bring r325915 back.
The tests that failed on a windows host have been fixed.

Original message:

Start setting dso_local for COFF.

With this there are still some GVs where we don't set dso_local
because setGVProperties is never called. I intend to fix that in
followup commits. This is just the bare minimum to teach
shouldAssumeDSOLocal what it should do for COFF.

llvm-svn: 325940
2018-02-23 19:30:48 +00:00
Mikhail Maltsev 7b1a950c4a [Sema] Classify conversions from enum to float as narrowing
Summary:
According to [dcl.init.list]p7:
  A narrowing conversion is an implicit conversion
  - ...
  - from an integer type or unscoped enumeration type to a
    floating-point type, except where the source is a constant
    expression and the actual value after conversion will fit into
    the target type and will produce the original value when
    converted back to the original type, or
  - ...

Currently clang does not handle the 'unscoped enumeration' case. This
patch fixes the corresponding check.

Reviewers: faisalv, rsmith, rogfer01

Reviewed By: rogfer01

Subscribers: rogfer01, cfe-commits

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

llvm-svn: 325668
2018-02-21 10:08:18 +00:00
Richard Smith 2e8a8629d6 Fix test failure on target where size_t is long long.
llvm-svn: 325540
2018-02-19 22:50:50 +00:00
Richard Smith 90c47cad22 [cxx_dr_status] Tests for CWG issues 641-687.
llvm-svn: 325475
2018-02-19 09:05:48 +00:00
Mikhail Maltsev 8d9acc5342 [Sema] Fix decltype of static data members
Summary:
According to the C++11 standard [dcl.type.simple]p4:
  The type denoted by decltype(e) is defined as follows:
  - if e is an unparenthesized id-expression or an unparenthesized
    class member access (5.2.5), decltype(e) is the type of the entity
    named by e.
    
Currently Clang handles the 'member access' case incorrectly for
static data members (decltype returns T& instead of T). This patch
fixes the issue.

Reviewers: faisalv, rsmith, rogfer01

Reviewed By: rogfer01

Subscribers: rogfer01, cfe-commits

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

llvm-svn: 325117
2018-02-14 11:34:25 +00:00
Jan Korous 3a98e51823 [Parser][FixIt] Better diagnostics for "typedef" instead of "typename" typo
rdar://problem/10214588

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

llvm-svn: 324607
2018-02-08 14:37:58 +00:00
Richard Smith 56ae0a67e8 DR126: partially implement the const-correct rules for exception handler matching.
While here, fix up the myriad other ways in which Sema's two "can this handler
catch that exception?" implementations get things wrong and unify them.

llvm-svn: 322431
2018-01-13 05:05:45 +00:00
Richard Smith 9fb4e60d7d PR33503: When a qualified name in a redeclaration names a prior declaration in
an inline namespace, update its semantic DeclContext to match.

We would previously get the semantic DeclContext wrong (pointing to the named
scope rather than the inline namespace within it), resulting in wrong lookup
results and linkage-related problems if the inline namespace was an anonymous
namespace.

llvm-svn: 321770
2018-01-03 23:03:54 +00:00
Jacob Bandes-Storch bb93578108 [Sema] Improve diagnostics for const- and ref-qualified member functions
(Re-submission of D39937 with fixed tests.)

Adjust wording for const-qualification mismatch to be a little more clear.

Also add another diagnostic for a ref qualifier mismatch, which previously produced a useless error (this error path is simply very old; see rL119336):

Before:
  error: cannot initialize object parameter of type 'X0' with an expression of type 'X0'

After:
  error: 'this' argument to member function 'rvalue' is an lvalue, but function has rvalue ref-qualifier

Reviewers: aaron.ballman

Reviewed By: aaron.ballman

Subscribers: lebedev.ri, cfe-commits

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

llvm-svn: 321609
2017-12-31 18:27:29 +00:00
Jacob Bandes-Storch 1dbc09363a Reverted 321592: [Sema] Improve diagnostics for const- and ref-qualified member functions
A few tests need to be fixed

llvm-svn: 321593
2017-12-31 05:13:03 +00:00
Jacob Bandes-Storch c7e67a04e0 [Sema] Improve diagnostics for const- and ref-qualified member functions
Summary:
Adjust wording for const-qualification mismatch to be a little more clear.

Also add another diagnostic for a ref qualifier mismatch, which previously produced a useless error (this error path is simply very old; see rL119336):

Before:
  error: cannot initialize object parameter of type 'X0' with an expression of type 'X0'

After:
  error: 'this' argument to member function 'rvalue' is an lvalue, but function has rvalue ref-qualifier

Reviewers: rsmith, aaron.ballman

Reviewed By: aaron.ballman

Subscribers: lebedev.ri, aaron.ballman, cfe-commits

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

llvm-svn: 321592
2017-12-31 04:49:39 +00:00
Faisal Vali a223d1c856 Diagnose the various invalid decl-specifiers on nontype template parameters.
The standard correctly forbids various decl-specifiers that dont make sense on non-type template parameters - such as the extern in:
    template<extern int> struct X;

This patch implements those restrictions (in a fashion similar to the corresponding checks on function parameters within ActOnParamDeclarator).

Credit goes to miyuki (Mikhail Maltsev) for drawing attention to this issue,  authoring the initial versions of this patch, and supporting the effort to re-engineer it slightly.  Thank you!

For details of how this patch evolved please see: https://reviews.llvm.org/D40705

llvm-svn: 321339
2017-12-22 03:50:55 +00:00
Aaron Ballman 8c20828b5c Re-commit r321223, which adds a printing policy to the ASTDumper.
This allows you to dump C++ code that spells bool instead of _Bool, leaves off the elaborated type specifiers when printing struct or class names, and other C-isms.

Fixes the -Wreorder issue and fixes the ast-dump-color.cpp test.

llvm-svn: 321310
2017-12-21 21:42:42 +00:00
Aaron Ballman 9d6501f6cd Reverting r321223 and its follow-up commit because of failing bots due to Misc/ast-dump-color.cpp.
llvm-svn: 321229
2017-12-20 23:17:29 +00:00
Aaron Ballman 207ee3d0a7 Add a printing policy to the ASTDumper.
This allows you to dump C++ code that spells bool instead of _Bool, leaves off the elaborated type specifiers when printing struct or class names, and other C-isms.

llvm-svn: 321223
2017-12-20 22:04:54 +00:00
Zhihao Yuan 00c9dfdfd0 P0620 follow-up: deducing `auto` from braced-init-list in new expr
Summary:
This is a side-effect brought in by p0620r0, which allows other placeholder types (derived from `auto` and `decltype(auto)`) to be usable in a `new` expression with a single-clause //braced-init-list// as its initializer (8.3.4 [expr.new]/2).  N3922 defined its semantics.

References:
 http://wg21.link/p0620r0
 http://wg21.link/n3922

Reviewers: rsmith, aaron.ballman

Reviewed By: rsmith

Subscribers: cfe-commits

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

llvm-svn: 320401
2017-12-11 18:29:54 +00:00
Hubert Tong bd72cd9577 Remove old concepts parsing code
Summary:
This is so we can implement concepts per P0734R0. Relevant failing test
cases are disabled.

Reviewers: hubert.reinterpretcast, rsmith, saar.raz, nwilson

Reviewed By: saar.raz

Subscribers: cfe-commits

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

Patch by Changyu Li!

llvm-svn: 319992
2017-12-07 00:34:20 +00:00
Richard Smith 527b3966d0 Preserve the "last diagnostic was suppressed" flag across SFINAE checks.
Sometimes we check the validity of some construct between producing a
diagnostic and producing its notes. Ideally, we wouldn't do that, but in
practice running code that "cannot possibly produce a diagnostic" in such a
situation should be safe, and reasonable factoring of some code requires it
with our current diagnostics infrastruture. If this does happen, a diagnostic
that's suppressed due to SFINAE should not cause notes connected to the prior
diagnostic to be suppressed.

llvm-svn: 319408
2017-11-30 08:18:21 +00:00
Aaron Ballman adf66b6174 Determine the attribute subject for diagnostics based on declarative information in DeclNodes.td. This greatly reduces the number of enumerated values used for more complex diagnostics; these are now only required when the "attribute only applies to" diagnostic needs to be generated manually as part of semantic processing.
This also clarifies some terminology used by the diagnostic (methods -> Objective-C methods, fields -> non-static data members, etc).

Many of the tests needed to be updated in multiple places for the diagnostic wording tweaks. The first instance of the diagnostic for that attribute is fully specified and subsequent instances cut off the complete list (to make it easier if additional subjects are added in the future for the attribute).

llvm-svn: 319002
2017-11-26 20:01:12 +00:00
Aaron Ballman 52a3ca9e29 The offsetof macro is intended to work with subobjects rather than simple identifiers designating a member, making the -Wextended-offsetof diagnostic obsolete as this construct is not an extension. Implements WG14 DR496.
llvm-svn: 318796
2017-11-21 19:25:38 +00:00
Hamza Sood 81fe14e4c3 [Modules TS] Added module re-export support.
This implements [dcl.modules.export] from the C++ Modules TS, which lets a module re-export another module with the "export import" syntax.
Differential Revision: https://reviews.llvm.org/D40270

llvm-svn: 318744
2017-11-21 09:42:42 +00:00
Richard Smith 4d629b8023 Fix missing -Wregister warning when 'register' is applied to a function parameter.
llvm-svn: 317140
2017-11-01 23:38:37 +00:00
Faisal Vali 81b756e6a3 [C++17] Fix PR34970 - tweak overload resolution for class template deduction-guides in line with WG21's p0620r0.
In order to identify the copy deduction candidate, I considered two approaches:
  - attempt to determine whether an implicit guide is a copy deduction candidate by checking certain properties of its subsituted parameter during overload-resolution.
  - using one of the many bits (WillHaveBody) from FunctionDecl (that CXXDeductionGuideDecl inherits from) that are otherwise irrelevant for deduction guides

After some brittle gymnastics w the first strategy, I settled on the second, although to avoid confusion and to give that bit a better name, i turned it into a member of an anonymous union.

Given this identification 'bit', the tweak to overload resolution was a simple reordering of the deduction guide checks (in SemaOverload.cpp::isBetterOverloadCandidate), in-line with Jason Merrill's p0620r0 drafting which made it into the working paper.  Concordant with that, I made sure the copy deduction candidate is always added.


References:
See https://bugs.llvm.org/show_bug.cgi?id=34970 
See http://wg21.link/p0620r0

llvm-svn: 316292
2017-10-22 14:45:08 +00:00
Erich Keane 80b0fb04a6 Fix nodiscard for volatile references
As reported here https://bugs.llvm.org/show_bug.cgi?id=34988
[[nodiscard]] warnings were not being suppressed for
volatile-ref return values.

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

llvm-svn: 316166
2017-10-19 15:58:58 +00:00
Aaron Ballman b95dc1f794 This test case was missing -fsyntax-only, so I've added it. NFC to the actual test contents, just how the test is executed.
llvm-svn: 316028
2017-10-17 20:49:30 +00:00
Erich Keane 883f22ef7e [Sema][Crash] Correctly handle an non-dependent noexcept expr in function template
It seems that all of the other templated cases are handled correctly,
however the function template case was not correctly handled. This
patch recovers from this condition by setting the function to noexcept
after diagnosing. Previously it simply set NoexceptExpr to null,
which caused an Assert when this was evaluated during substitution.

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

llvm-svn: 315638
2017-10-12 23:01:53 +00:00
Richard Smith 18057cb34c [Modules TS] Diagnose missing/duplicate module-declaration.
llvm-svn: 315397
2017-10-11 00:36:56 +00:00
Richard Smith d97d35e150 [Modules TS] Diagnose attempts to enter module implementation units without the module interface being available.
llvm-svn: 315381
2017-10-10 22:35:27 +00:00
Richard Smith becb92dec8 [Modules TS] Module ownership semantics for redeclarations.
When declaring an entity in the "purview" of a module, it's never a
redeclaration of an entity in the purview of a default module or in no module
("in the global module"). Don't consider those other declarations as possible
redeclaration targets if they're not visible, and reject any cases where we
pick a prior visible declaration that violates this rule.

This reinstates r315251 and r315256, reverted in r315309 and r315308
respectively, tweaked to avoid triggering a linkage calculation when declaring
implicit special members (this exposed our pre-existing issue with typedef
names for linkage changing the linkage of types whose linkage has already been
computed and cached in more cases). A testcase for that regression has been
added in r315366.

llvm-svn: 315379
2017-10-10 22:33:17 +00:00
Eric Liu f01516db8d Revert "[Modules TS] Module ownership semantics for redeclarations."
This reverts commit r315251. See the original commit thread for reason.

llvm-svn: 315309
2017-10-10 13:09:40 +00:00
Richard Smith b87720b77a [Modules TS] Module ownership semantics for redeclarations.
When declaring an entity in the "purview" of a module, it's never a
redeclaration of an entity in the purview of a default module or in no module
("in the global module"). Don't consider those other declarations as possible
redeclaration targets if they're not visible, and reject any cases where we
pick a prior visible declaration that violates this rule.

llvm-svn: 315251
2017-10-09 23:42:09 +00:00
Saleem Abdulrasool 729379a1e1 Driver: hoist the `wchar_t` handling to the driver
Move the logic for determining the `wchar_t` type information into the
driver.  Rather than passing the single bit of information of
`-fshort-wchar` indicate to the frontend the desired type of `wchar_t`
through a new `-cc1` option of `-fwchar-type` and indicate the
signedness through `-f{,no-}signed-wchar`.  This replicates the current
logic which was spread throughout Basic into the
`RenderCharacterOptions`.

Most of the changes to the tests are to ensure that the frontend uses
the correct type.  Add a new test set under `test/Driver/wchar_t.c` to
ensure that we calculate the proper types for the various cases.

llvm-svn: 315126
2017-10-06 23:09:55 +00:00
Richard Smith ac63d63543 Add a "vexing parse" warning for ambiguity between a variable declaration and a
function-style cast.

This fires for cases such as

  T(x);

... where 'x' was previously declared and T is a type. This construct declares
a variable named 'x' rather than the (probably expected) interpretation of a
function-style cast of 'x' to T.

llvm-svn: 314570
2017-09-29 23:57:25 +00:00
Richard Smith 263a0a33cc Don't warn about runtime behavior problems in variable initializers that we
know are going to be constant-evaluated.

Any relevant diagnostics should be produced by constant expression evaluation.

llvm-svn: 314067
2017-09-23 18:27:11 +00:00
Richard Smith cdb06f2150 Correctly compute linkage for members of internal linkage classes.
We used to give such members no linkage instead of giving them the linkage of
the class.

llvm-svn: 314054
2017-09-23 04:02:17 +00:00
Richard Smith df963a38a9 DR1113: anonymous namespaces formally give their contents internal linkage.
This doesn't affect our code generation in any material way -- we already give
such declarations internal linkage from a codegen perspective -- but it has
some subtle effects on code validity.

We suppress the 'L' (internal linkage) marker for mangled names in anonymous
namespaces, because it is redundant (the information is already carried by the
namespace); this deviates from GCC's behavior if a variable or function in an
anonymous namespace is redundantly declared 'static' (where GCC does include
the 'L'), but GCC's behavior is incoherent because such a declaration can be
validly declared with or without the 'static'.

We still deviate from the standard in one regard here: extern "C" declarations
in anonymous namespaces are still granted external linkage. Changing those does
not appear to have been an intentional consequence of the standard change in
DR1113.

llvm-svn: 314037
2017-09-22 22:21:44 +00:00
Richard Smith 7ff8304db7 Closure types have no name (and can't have a typedef name for linkage
purposes), so they never formally have linkage.

llvm-svn: 313957
2017-09-22 04:33:20 +00:00
Richard Smith aa6ce34141 Fix tracking of whether a destructor would be deleted.
I've been unable to find any cases whose behavior is actually changed by this,
but only because an implicitly deleted destructor also results in it being
impossible to have a trivial (non-deleted) copy constructor, which the place
where this really matters (choosing whether to pass a class in registers)
happens to also check.

llvm-svn: 313948
2017-09-22 01:04:22 +00:00
Richard Smith 405e2dbf37 Implement C++ [basic.link]p8.
If a function or variable has a type with no linkage (and is not extern "C"),
any use of it requires a definition within the same translation unit; the idea
is that it is not possible to define the entity elsewhere, so any such use is
necessarily an error.

There is an exception, though: some types formally have no linkage but
nonetheless can be referenced from other translation units (for example, this
happens to anonymous structures defined within inline functions). For entities
with those types, we suppress the diagnostic except under -pedantic.

llvm-svn: 313729
2017-09-20 07:22:00 +00:00
Richard Smith f26c54f9ce Add target triple to improve the happiness of MSVC buildbots.
llvm-svn: 312749
2017-09-07 22:07:52 +00:00
Richard Smith b8c419085f Add IDNS_Tag to C++ declarations that conflict with tag declarations.
Fixes some accepts-invalids with tags and other declarations declared in the
same scope.

llvm-svn: 312743
2017-09-07 20:22:00 +00:00
Richard Smith 1363e8f6ed P0702R1: in class template argument deduction from a list of one element, if
that element's type is (or is derived from) a specialization of the deduced
template, skip the std::initializer_list special case.

llvm-svn: 312703
2017-09-07 07:22:36 +00:00
Richard Smith 80acd0fd0b [modules ts] Add test for [basic.link]p3.
llvm-svn: 312696
2017-09-07 05:29:39 +00:00