2699 Commits

Author SHA1 Message Date
Fangrui Song
dd85c6cce4
[Sema] Add -Wc++11-narrowing-const-reference (#76094)
https://github.com/llvm/llvm-project/pull/75332 diagnosed narrowing
involving const reference. Our depot has hundreds if not thousands of
breakages

(https://github.com/llvm/llvm-project/pull/75332#issuecomment-1864757240).
Add a subgroup of -Wc++11-narrowing to help users gradually fix their
issues without regressing the existing -Wc++11-narrowing diagnostics.
2023-12-22 11:28:07 -05:00
Fangrui Song
57f42a8765 Revert "[clang] Substitute alias templates from correct context (#75069)"
This reverts commit dbf67ea1d334d2114fe49701a8f4b8afd536e39f.

It caused spurious "out-of-line definition of 'operator=' does not match
any declaration in" error.
https://github.com/llvm/llvm-project/pull/75069#issuecomment-1856581259
2023-12-14 14:57:15 -08:00
Mariya Podchishchaeva
dbf67ea1d3
[clang] Substitute alias templates from correct context (#75069)
Current context set to where alias was met, not where it is declared
caused incorrect access check in case alias referenced private members
of the parent class.
This is a recommit of 6b1aa31 with a slight modification in order to fix
reported regression.

Fixes https://github.com/llvm/llvm-project/issues/41693
2023-12-13 08:50:43 +01:00
Krystian Stasiowski
29bd78b2f6
[Clang][Sema] Diagnose friend function specialization definitions (#72863)
Per [[class.friend]p6](http://eel.is/c++draft/class.friend#6) a friend
function shall not be defined if its name isn't unqualified. A
_template-id_ is not a name, meaning that a friend function
specialization does not meet this criteria and cannot be defined.

GCC, MSVC, and EDG all consider friend function specialization
definitions to be invalid de facto explicit specializations and diagnose
them as such.

Instantiating a dependent friend function specialization definition
[currently sets off an assert](https://godbolt.org/z/Krqdq95hY) in
`FunctionDecl::setFunctionTemplateSpecialization`. This happens because
we do not set the `TemplateSpecializationKind` of the `FunctionDecl`
created by template argument deduction to `TSK_ExplicitSpecialization`
for friend functions
[here](https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/SemaTemplate.cpp#L9600).
I changed the assert condition because I believe this is the correct
behavior.
2023-12-11 06:35:57 -08:00
Vlad Serebrennikov
6ed9a81f7e
[clang][NFC] Refactor expected directives in C++ DRs 2000-2799 (#74921)
This patch continues the work started with ea5b1ef016d020c37f903d6c7d4f623be975dab8. See that commit and its
corresponding PR for details.
2023-12-09 12:53:48 +04:00
Vlad Serebrennikov
57eb2054e3 [clang][NFC] Fill in historical data on when C++ DRs 2000-2799 were fixed 2023-12-09 11:12:54 +03:00
Vlad Serebrennikov
76ee344769
[clang][NFC] Refactor expected directives in C++ DRs 700-1999 (#74767)
This patch continues the work started with ea5b1ef016d020c37f903d6c7d4f623be975dab8. See that commit and its
corresponding PR for details.
2023-12-08 12:10:57 +04:00
Vlad Serebrennikov
c79f94d851 [clang][NFC] Fill in historical data on when C++ DRs 700-1999 were fixed 2023-12-08 00:38:42 +03:00
Podchishchaeva, Mariya
565dddec63 Revert "[clang] Substitute alias templates from correct context (#74335)"
It was reported in the PR that commit caused clang giving errors for
code previously considered valid.
This reverts commit 6b1aa319754e76366edd88e10034e0539710d946.
2023-12-06 08:49:17 -08:00
Mariya Podchishchaeva
6b1aa31975
[clang] Substitute alias templates from correct context (#74335)
Current context set to where alias was met, not where it is declared
caused incorrect access check in case alias referenced private members
of the parent class.

Fixes https://github.com/llvm/llvm-project/issues/41693
2023-12-06 11:14:17 +01:00
Vlad Serebrennikov
af03e29289
[clang][NFC] Refactor expected directives in C++ DRs 600-699 (#74477)
[clang][NFC] Refactor expected directives in C++ DRs 600-699

This patch continues the work started with ea5b1ef016.
See that commit and its corresponding PR for details.
2023-12-05 23:49:44 +04:00
Vlad Serebrennikov
94708fbc0f [clang][NFC] Fill in historical data on when C++ DRs 600-699 were fixed 2023-12-05 17:16:10 +03:00
Vlad Serebrennikov
d11d38cb09
[clang][NFC] Refactor expected directives in C++ DRs 500-599 (#74373)
This patch continues the work started with ea5b1ef016d020c37f903d6c7d4f623be975dab8. See that commit and its
corresponding PR for details.
2023-12-05 11:23:32 +04:00
Vlad Serebrennikov
e77bfaaf9d [clang][NFC] Fill in historical data on when C++ DRs 500-599 were fixed 2023-12-05 00:42:13 +03:00
Vlad Serebrennikov
c556c9c379
[clang][NFC] Refactor expected directives in C++ DRs 400-499 (#74311)
This patch continues the work started with ea5b1ef016d020c37f903d6c7d4f623be975dab8. See that commit and its corresponding PR for details.
2023-12-04 18:00:09 +04:00
Vlad Serebrennikov
f9afe4049a [clang][NFC] Fill in historical data on when C++ DRs 400-499 were fixed 2023-12-04 15:15:40 +03:00
Chuanqi Xu
db3d0e4dfa [C++20] [Modules] Don't diagnose on invisible namesapce
Close https://github.com/llvm/llvm-project/issues/73893

As the issue shows, generally, the diagnose information for
invisible namespace is confusing more than helpful. Also this patch
implements the same solution as suggested in the issue: don't diagnose
on invisible namespace.
2023-12-04 17:05:27 +08:00
Vlad Serebrennikov
bc51a36fd6
[clang][NFC] Refactor expected directives in C++ DRs 300-399 (#74243)
This patch continues the work started with ea5b1ef016d020c37f903d6c7d4f623be975dab8. See that commit and its corresponding PR for details.
2023-12-03 18:35:49 +04:00
Vlad Serebrennikov
599cba3e7c [clang][NFC] Fill in historical data on when C++ DRs 300-399 were fixed 2023-12-03 16:48:53 +03:00
Vlad Serebrennikov
19bef888a8 [clang][NFC] Adjust expected directives in DR tests further
This is a follow-up to 96070e1e4c13f53c2cef8178d64e206162923f54, where long long case was hidden by a different error.

Addresses bot failures:
https://lab.llvm.org/buildbot/#/builders/123/builds/23355
2023-12-03 09:02:58 +03:00
Vlad Serebrennikov
96070e1e4c [clang][NFC] Adjust expected directives in DR tests
This is a follow-up to 0c06e8745f131d867c566f4d35a7a04e24b4a075, which accomodated expected directives for 32-bit ARM and Windows platforms.

Addressed bot failures:
https://lab.llvm.org/buildbot/#/builders/123/builds/23355
https://lab.llvm.org/buildbot/#/builders/245/builds/17458
2023-12-03 00:21:53 +03:00
Vlad Serebrennikov
0c06e8745f [clang][NFC] Refactor expected directives in C++ DRs 200-299
This patch continues the work started with ea5b1ef016d020c37f903d6c7d4f623be975dab8. See that commit and its corresponding PR for details.
2023-12-02 21:25:54 +03:00
Vlad Serebrennikov
2f9c922a12 [clang][NFC] Fill in historical data on when C++ DRs 200-299 were fixed 2023-12-02 21:25:00 +03:00
cor3ntin
f40d25151c
[Clang] Implement P2308R1 - Template Parameter Initialization. (#73103)
https://wiki.edg.com/pub/Wg21kona2023/StrawPolls/p2308r1.html

This implements P2308R1 as a DR and resolves CWG2459, CWG2450 and
CWG2049.


Fixes #73666
Fixes #58434 
Fixes #41227
Fixes #49978
Fixes #36296
2023-12-01 17:44:22 +01:00
Vlad Serebrennikov
6ab7662f35
[clang][NFC] Refactor expected directives in C++ DRs 100-199 (#74061)
This patch continues the work started with ea5b1ef016d020c37f903d6c7d4f623be975dab8. See that commit and its corresponding PR for details.
2023-12-01 17:56:27 +04:00
Vlad Serebrennikov
289fe74ddb [clang][NFC] Fill in historical data on when C++ DRs 100-199 were fixed 2023-12-01 13:43:22 +03:00
Vlad Serebrennikov
ea5b1ef016
[clang][NFC] Refactor expected directives in C++ DRs 1-99 (#73879)
This patch converts (almost) every expected directive in `test/CXX/drs/dr0xx.cpp` into either `@-1` form (when directive immediately follow the line diagnostic is pointing out to), or `@#<marker>` form (when directive is placed away from the line diagnostic is pointing out to). It also converts directive to match exactly one diagnostic, as opposed to matching multiple. Error messages are expanded to exactly match compiler output. `#if __cplusplus` guarding directives are replaced with respective prefixes (e.g. `since-cxx17`).

All aforementioned changes serve a purpose of making it easier to reconstruct expected compiler output, which should also make it a bit easier to grasp the gist of those already non-trivial tests due to their nature of testing corner cases of the language.
2023-11-30 21:16:33 +04:00
Vlad Serebrennikov
2323b541e1 [clang][NFC] Bring back missing lines from DR52 test
A follow-up for bf2e05c7fbc739cd9b9086163303f846ee2806d2
2023-11-30 03:41:18 +03:00
Vlad Serebrennikov
bf2e05c7fb [clang][NFC] Fill in historical data on when C++ DR 1-99 were fixed 2023-11-30 02:25:15 +03:00
cor3ntin
205f53010d
[Clang] CWG2789 Overload resolution with implicit and explicit object… (#73493)
… member functions

Implement the resolution to CWG2789 from
https://wiki.edg.com/pub/Wg21kona2023/StrawPolls/p3046r0.html

The DR page is not updated because the issue has not made it to a
published list yet.
2023-11-28 13:30:18 +01:00
cor3ntin
fdefe88bff
[Clang] Improve support for expression messages in static_assert (#73234)
- Support non-member functions and callable objects for size and data().
We previously tried to (badly) pick the best overload ourselves, in a
way that would only support member functions. We now leave clang
construct an unresolved member expression and call that, properly
performing overload resolution with callable objects and static
functions, consistent with the logic for `get` calls for structured
bindings.
- Support UDLs as message expression.
- Add tests and mark CWG2798 as resolved
2023-11-28 04:28:57 +01:00
Krystian Stasiowski
979eb558dd
[Clang][Sema] Differentiate between partial/explicit specializations when diagnosing unexpanded packs (#72015)
This adds `UnexpandedParameterPackContext::UPPC_ExplicitSpecialization`
and passes it to `DiagnoseUnexpandedParameterPack` when checking
class/variable template explicit specializations.

Right now we don't check for unexpanded packs in function template
explicit specializations at all, so I will be addressing that in a
followup PR.
2023-11-16 10:46:44 +01:00
Antonio Frighetto
970bf07d0b [clang][CodeGen] Ensure consistent mustprogress attribute emission
Emission of `mustprogress` attribute previously occurred only within
`EmitFunctionBody`, after generating the function body. Other routines
for function body creation may lack the attribute, potentially leading
to suboptimal optimizations later in the pipeline. Attribute emission
is now anticipated prior to generating the function body.

Fixes: https://github.com/llvm/llvm-project/issues/69833.
2023-11-11 09:43:03 +01:00
Chuanqi Xu
0e7b30fa82 [C++20] [Modules] Enhance better diagnostic for implicit global module and module partitions
Due to an oversight, when users use an unexported declaration from
implicit global module, the diagnostic will show "please #include"
instead of "please import". This patch corrects the behavior.

Also previously, when users use an unexported declarations from module
partitions, the diagnostic message will always show the partition name
no matter if that partition name is visible to the users. Now the users
may only see the partition name if the users are in the same module with
the partition unit.
2023-11-10 10:58:07 +08:00
Jessica Clarke
f9ead46931
[AST] Only dump desugared type when visibly different (#65214)
These are an artifact of how types are structured but serve little
purpose, merely showing that the type is sugared in some way. For
example, ElaboratedType's existence means struct S gets printed as
'struct S':'struct S' in the AST, which is unnecessary visual clutter.
Note that skipping the second print when the types have the same string
matches what we do for diagnostics, where the aka will be skipped.
2023-10-26 19:28:28 +01:00
Shafik Yaghmour
b8e06933a2
[Clang] Ensure zero-init is not overridden when initializing a base class in a constant expression context (#70150)
During constant evaluation when value-initializing a class if the base
class was default-initialized it would undue the previously
zero-initialized class members. This fixes the way we handle default
initialization to avoid initializing over an already initialized member
to an indeterminate value.

Fixes: https://github.com/llvm/llvm-project/issues/69890
2023-10-25 10:18:40 -07:00
cor3ntin
20d97adfd3
[Clang] Mark declarators invalid in the presence of ill-formed explicit parameters. (#70018)
To avoid crashes later in sema.

Fixes #69962
Fixes #69838
2023-10-24 20:42:31 +02:00
Utkarsh Saxena
a87638596a
Revert tests missed in b997ff41c11cc69cfcb6c8a3ed39ed47229cf891 2023-10-23 23:53:35 +02:00
Utkarsh Saxena
9330261143
Use the correct namespace for looking up matching operator!= (#68922)
`S.getScopeForContext` determins the **active** scope associated with
the given `declContext`.
This fails to find the matching `operator!=` if candidate `operator==`
was found via ADL since that scope is not active.

Instead, just directly lookup using the namespace decl of `operator==`

Fixes #68901
2023-10-23 14:10:06 +02:00
Aaron Ballman
84a3aadf0f Diagnose use of VLAs in C++ by default
Reapplication of 7339c0f782d5c70e0928f8991b0c05338a90c84c with a fix
for a crash involving arrays without a size expression.

Clang supports VLAs in C++ as an extension, but we currently only warn
on their use when you pass -Wvla, -Wvla-extension, or -pedantic.
However, VLAs as they're expressed in C have been considered by WG21
and rejected, are easy to use accidentally to the surprise of users
(e.g., https://ddanilov.me/default-non-standard-features/), and they
have potential security implications beyond constant-size arrays
(https://wiki.sei.cmu.edu/confluence/display/c/ARR32-C.+Ensure+size+arguments+for+variable+length+arrays+are+in+a+valid+range).
C++ users should strongly consider using other functionality such as
std::vector instead.

This seems like sufficiently compelling evidence to warn users about
VLA use by default in C++ modes. This patch enables the -Wvla-extension
diagnostic group in C++ language modes by default, and adds the warning
group to -Wall in GNU++ language modes. The warning is still opt-in in
C language modes, where support for VLAs is somewhat less surprising to
users.

RFC: https://discourse.llvm.org/t/rfc-diagnosing-use-of-vlas-in-c/73109
Fixes https://github.com/llvm/llvm-project/issues/62836
Differential Revision: https://reviews.llvm.org/D156565
2023-10-20 13:10:03 -04:00
Aaron Ballman
f5043f46c0 Revert "Diagnose use of VLAs in C++ by default"
This reverts commit 7339c0f782d5c70e0928f8991b0c05338a90c84c.

Breaks bots:
https://lab.llvm.org/buildbot/#/builders/139/builds/51875
https://lab.llvm.org/buildbot/#/builders/164/builds/45262
2023-10-20 10:00:18 -04:00
Aaron Ballman
7339c0f782 Diagnose use of VLAs in C++ by default
Clang supports VLAs in C++ as an extension, but we currently only warn
on their use when you pass -Wvla, -Wvla-extension, or -pedantic.
However, VLAs as they're expressed in C have been considered by WG21
and rejected, are easy to use accidentally to the surprise of users
(e.g., https://ddanilov.me/default-non-standard-features/), and they
have potential security implications beyond constant-size arrays
(https://wiki.sei.cmu.edu/confluence/display/c/ARR32-C.+Ensure+size+arguments+for+variable+length+arrays+are+in+a+valid+range).
C++ users should strongly consider using other functionality such as
std::vector instead.

This seems like sufficiently compelling evidence to warn users about
VLA use by default in C++ modes. This patch enables the -Wvla-extension
diagnostic group in C++ language modes by default, and adds the warning
group to -Wall in GNU++ language modes. The warning is still opt-in in
C language modes, where support for VLAs is somewhat less surprising to
users.

RFC: https://discourse.llvm.org/t/rfc-diagnosing-use-of-vlas-in-c/73109
Fixes https://github.com/llvm/llvm-project/issues/62836
Differential Revision: https://reviews.llvm.org/D156565
2023-10-20 09:50:21 -04:00
Utkarsh Saxena
47747da634
[clang] Handle templated operators with reversed arguments (#69595)
https://github.com/llvm/llvm-project/pull/68999 correctly computed
conversion sequence for reversed args to a template operators. This was
a breaking change as code, previously accepted in C++17, starts to break
in C++20.

Example:
```cpp
struct P {};
template<class S> bool operator==(const P&, const S &);

struct A : public P {};
struct B : public P {};
bool check(A a, B b) { return a == b; }  // This is now ambiguous in C++20.
```

In order to minimise widespread breakages, as a clang extension, we had
previously accepted such ambiguities with a warning
(`-Wambiguous-reversed-operator`) for non-template operators. Due to the
same reasons, we extend this relaxation for template operators.

Fixes https://github.com/llvm/llvm-project/issues/53954
2023-10-20 14:40:25 +02:00
Dmitry Chernenkov
a3a0f59a1e Revert "Correctly compute conversion seq for args to fn with reversed param order (#68999)"
This reverts commit e6d0b126c824222fca2f31a2ba571c2ee2bb4760.

See PR for reason

https://github.com/llvm/llvm-project/pull/68999#issuecomment-1768541660
2023-10-18 14:13:48 +00:00
Utkarsh Saxena
e6d0b126c8
Correctly compute conversion seq for args to fn with reversed param order (#68999)
We associated conversion seq for args (when reversed) to the wrong
index.
This lead to clang believing reversed `operator==` a worse overload
candidate than the `operator==` without reversed args when both these
candidate were ambiguous.

Fixes https://github.com/llvm/llvm-project/issues/53954
2023-10-17 20:53:42 +02:00
Krystian Stasiowski
3a3b84b180
[clang] remove ClassScopeFunctionSpecializationDecl (#66636)
This removes the `ClassScopeFunctionSpecializationDecl` `Decl` node, and
instead uses `DependentFunctionTemplateSpecializationInfo` to handle
such declarations. `DependentFunctionTemplateSpecializationInfo` is also
changed to store a `const ASTTemplateArgumentListInfo*` to be more in
line with `FunctionTemplateSpecializationInfo`.

This also changes `FunctionDecl::isFunctionTemplateSpecialization` to
return `true` for dependent specializations, and
`FunctionDecl::getTemplateSpecializationKind`/`FunctionDecl::getTemplateSpecializationKindForInstantiation`
to return `TSK_ExplicitSpecialization` for non-friend dependent
specializations (the same behavior as dependent class scope
`ClassTemplateSepcializationDecl` & `VarTemplateSepcializationDecl`).
2023-10-07 10:55:31 +04:00
Botond István Hprváth
66c19167f1
[clang] Choose non-templated ctor as deduction guide unambiguously (#66487)
If there are two guides, one of them generated from a non-templated
constructor
and the other from a templated constructor, then the standard gives
priority to
the first. Clang detected ambiguity before, now the correct guide is
chosen.
The correct behavior is described in this paper:
http://wg21.link/P0620R0

Example for the bug: http://godbolt.org/z/ee3e9qG78

As an unrelated minor change, fix the issue
https://github.com/llvm/llvm-project/issues/64020,
which could've led to incorrect behavior if further development inserted
code after a call to
`isAddressSpaceSubsetOf()`, which specified the two parameters in the
wrong order.

---------

Co-authored-by: hobois <horvath.botond.istvan@gmial.com>
2023-10-04 09:11:43 -07:00
Nouman Amir
af16a4e131 Improve error message for constexpr constructors of virtual base classes
The changes are for better diagnostic/error-messages. The error message
of Clang, MSVC, and GCC were compared and MSVC gives more detailed
error message so that is used now.

Fixes https://github.com/llvm/llvm-project/issues/64843
Differential Revision: https://reviews.llvm.org/D158540
2023-10-03 15:06:08 -04:00
Vlad Serebrennikov
c2fd3ebe83
[clang] Add test for CWG2267 (#67931)
https://cplusplus.github.io/CWG/issues/2267.html
Related: #63416
2023-10-02 20:00:41 +04:00
Vlad Serebrennikov
1a3a1d9674
[clang] Add check for duplicates to make_cxx_dr_status script (#67969)
While working on #67965, I stumbled upon the fact that `make_cxx_dr_status` script doesn't check for duplicated comment (last comment wins), so I added this check.

It even found another instance of duplicated comment: CWG1223 was marked as CWG1227. I fixed status of the former.
2023-10-02 18:34:37 +04:00