[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-14 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

> I looked at this a bit and the change that increases the constexpr 
> restrictions is that ext_defaulted_comparison_constexpr_mismatch (which was 
> added in https://reviews.llvm.org/D146090) became 
> err_incorrect_defaulted_comparison_constexpr?

Yes, it was intentional change. And the diagnostic you're seeing is valid for 
C++20. Prior C++23 defaulted function that invokes non-constexpr function under 
the hood cannot be marked constexpr. Since relaxing that was made in 
https://reviews.llvm.org/D146090 is a part of P2448R2, but other parts 
implemented by this patch are C++23-only due to the problems I described in 
https://github.com/llvm/llvm-project/pull/77753#issuecomment-1979028701 , I've 
made all parts of P2448R2 consistent.
I would suggest opening an issue here on GitHub to discuss whether we would 
like to make the feature inconsistent.

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-13 Thread Amy Huang via cfe-commits

amykhuang wrote:

I looked at this a bit and the change that increases the constexpr restrictions 
is that `ext_defaulted_comparison_constexpr_mismatch` (which was added in 
https://reviews.llvm.org/D146090) became 
`err_incorrect_defaulted_comparison_constexpr`?

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-13 Thread Amy Huang via cfe-commits

amykhuang wrote:

Whoops, not very familiar with git pull requests, I guess. actually reapplying 
the commit now

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-13 Thread via cfe-commits

dyung wrote:

> Nevermind, unreverted since there appear to be newer tests that use this 
> patch.

@amykhuang your unrevert (9bfa506d69b9177ced00b69bf94b28038b063d6d) appears to 
be an empty commit? Was that intended?

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-13 Thread Amy Huang via cfe-commits

amykhuang wrote:

Nevermind, unreverted since there appear to be newer tests that use this patch. 

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-13 Thread Amy Huang via cfe-commits

amykhuang wrote:

I'm assuming this behavior is unintended? Sorry for the late revert

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-13 Thread Amy Huang via cfe-commits

amykhuang wrote:

Hi, this is causing failures for Chrome, building with c++20:

```
$ cat t.cc
template  class StrongAlias {
  friend constexpr bool operator==(const StrongAlias &, const StrongAlias &) = 
default;
  Type value;
};

class Token {};
bool operator==(const Token&, const Token&);

StrongAlias a;

$ clang -std=c++20 t.cc
t.cc:2:3: error: defaulted definition of equality comparison operator cannot be 
declared constexpr because it invokes a non-constexpr comparison function 
2 |   friend constexpr bool operator==(const StrongAlias &, const 
StrongAlias &) = default;
  |   ^
t.cc:9:20: note: in instantiation of template class 'StrongAlias' 
requested here
9 | StrongAlias a;
  |^
t.cc:3:8: note: non-constexpr comparison function would be used to compare 
member 'value'
3 |   Type value;
  |^
t.cc:7:6: note: non-constexpr comparison function declared here
7 | bool operator==(const Token&, const Token&);
  |  ^
1 error generated.
```

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-11 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

Yeah, I think this is related to 
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0859r0.html and I 
think this comment from @zygoloid might be related as well: 
https://github.com/llvm/llvm-project/issues/12223#issuecomment-980903515

It's possible this is valid for Clang to reject because of eager instantiation, 
but I'm not 100% convinced yet either. CC @erichkeane @hubert-reinterpretcast 
as well

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-11 Thread Stephan Bergmann via cfe-commits

stbergmann wrote:

I think the discourse thread [Clang is overly aggressive when evaluating 
constexpr 
functions](https://discourse.llvm.org/t/clang-is-overly-aggressive-when-evaluating-constexpr-functions/67006)
 is relevant here.

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-11 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

Ok, now I looked at it a bit more, and I think this is expected due to the 
change and how clang behaved before this patch. After this patch implicit 
destructor of S, i.e. `~S` becomes `constexpr`. It used to be not `constexpr` 
because neither `P` nor `B` had `constexpr` destructors. clang defines and 
emits errors for constexpr defaulted members due to this bit here:
https://github.com/llvm/llvm-project/blob/0ef61ed54dca2e974928c55b2144b57d4c4ff621/clang/lib/Sema/SemaDeclCXX.cpp#L7225

So, once I manually change this example to force `~S()` to be `constexpr`, 
older clang produces the same error:
```
template struct P {
cosntexpr ~P() { p->f(); } // add constexpr
T * p;
};
struct X;
struct B { virtual constexpr ~B(); }; // add constexpr
struct S: B { P x; }; // now all bases and members have constexpr 
destructors, ~S() is constexpr
```
Demo https://godbolt.org/z/rT3bWMdqz (note I took 18.1.0 clang which doesn't 
have P2448R2 implementation). 

I'm not quite sure the error itself is correct, I've got to educate myself 
about standard matters a bit more to understand this, but no other compiler 
errors on this https://godbolt.org/z/Ehhn5sno7.

cc @AaronBallman , @cor3ntin, @zygoloid in case you can weigh in here

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-11 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

> to fail, which I think is not intentional?

No, it is not. Fails only for c++23 now. I'm looking. 

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-10 Thread Stephan Bergmann via cfe-commits

stbergmann wrote:

This change started to cause
```
$ cat test.cc
template struct P {
~P() { p->f(); }
T * p;
};
struct X;
struct B { virtual ~B(); };
struct S: B { P x; };
```
```
$ clang++ -std=c++23 -fsyntax-only test.cc
test.cc:2:13: error: member access into incomplete type 'X'
2 | ~P() { p->f(); }
  | ^
test.cc:7:8: note: in instantiation of member function 'P::~P' requested here
7 | struct S: B { P x; };
  |^
test.cc:5:8: note: forward declaration of 'X'
5 | struct X;
  |^
1 error generated.
```
to fail, which I think is not intentional?

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-07 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon closed 
https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-06 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman approved this pull request.

LGTM, thank you for the implementation!

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-06 Thread Mariya Podchishchaeva via cfe-commits


@@ -2809,10 +2813,13 @@ def note_non_literal_virtual_base : 
Note<"%select{struct|interface|class}0 "
   "with virtual base %plural{1:class|:classes}1 is not a literal type">;
 def note_constexpr_virtual_base_here : Note<"virtual base class declared 
here">;
 def err_constexpr_non_literal_return : Error<
-  "%select{constexpr|consteval}0 function's return type %1 is not a literal 
type">;
+  "%select{constexpr|consteval}0 function with non-literal return type %1 is a 
C++23 extension">;
+def warn_cxx20_compat_constexpr_non_literal_return : Warning<
+  "%select{constexpr|consteval}0 function with non-literal return type %1 is 
incompatible with C++ standards before C++23">, InGroup, 
DefaultIgnore;
 def err_constexpr_non_literal_param : Error<
-  "%select{constexpr|consteval}2 %select{function|constructor}1's %ordinal0 
parameter type %3 is "
-  "not a literal type">;
+  "%select{constexpr|consteval}2 %select{function|constructor}1 with %ordinal0 
non-literal parameter type %3 is a C++23 extension">;
+def warn_cxx20_compat_constexpr_non_literal_param : Warning<

Fznamznon wrote:

Done.

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-06 Thread Mariya Podchishchaeva via cfe-commits


@@ -2809,10 +2813,13 @@ def note_non_literal_virtual_base : 
Note<"%select{struct|interface|class}0 "
   "with virtual base %plural{1:class|:classes}1 is not a literal type">;
 def note_constexpr_virtual_base_here : Note<"virtual base class declared 
here">;
 def err_constexpr_non_literal_return : Error<
-  "%select{constexpr|consteval}0 function's return type %1 is not a literal 
type">;
+  "%select{constexpr|consteval}0 function with non-literal return type %1 is a 
C++23 extension">;
+def warn_cxx20_compat_constexpr_non_literal_return : Warning<

Fznamznon wrote:

Done.

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-06 Thread Mariya Podchishchaeva via cfe-commits


@@ -2809,10 +2813,13 @@ def note_non_literal_virtual_base : 
Note<"%select{struct|interface|class}0 "
   "with virtual base %plural{1:class|:classes}1 is not a literal type">;
 def note_constexpr_virtual_base_here : Note<"virtual base class declared 
here">;
 def err_constexpr_non_literal_return : Error<
-  "%select{constexpr|consteval}0 function's return type %1 is not a literal 
type">;
+  "%select{constexpr|consteval}0 function with non-literal return type %1 is a 
C++23 extension">;
+def warn_cxx20_compat_constexpr_non_literal_return : Warning<
+  "%select{constexpr|consteval}0 function with non-literal return type %1 is 
incompatible with C++ standards before C++23">, InGroup, 
DefaultIgnore;
 def err_constexpr_non_literal_param : Error<
-  "%select{constexpr|consteval}2 %select{function|constructor}1's %ordinal0 
parameter type %3 is "
-  "not a literal type">;
+  "%select{constexpr|consteval}2 %select{function|constructor}1 with %ordinal0 
non-literal parameter type %3 is a C++23 extension">;

Fznamznon wrote:

Done.

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-06 Thread Mariya Podchishchaeva via cfe-commits


@@ -2774,9 +2774,13 @@ def err_constexpr_tag : Error<
 def err_constexpr_dtor : Error<
   "destructor cannot be declared %sub{select_constexpr_spec_kind}0">;
 def err_constexpr_dtor_subobject : Error<
-  "destructor cannot be declared %sub{select_constexpr_spec_kind}0 because "
+  "destructor cannot be declared %sub{select_constexpr_spec_kind}0 before 
C++23 because "
   "%select{data member %2|base class %3}1 does not have a "
   "constexpr destructor">;
+def warn_cxx20_compat_constexpr_dtor_subobject : Warning<

Fznamznon wrote:

Done too.

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-06 Thread Mariya Podchishchaeva via cfe-commits


@@ -2809,10 +2813,13 @@ def note_non_literal_virtual_base : 
Note<"%select{struct|interface|class}0 "
   "with virtual base %plural{1:class|:classes}1 is not a literal type">;
 def note_constexpr_virtual_base_here : Note<"virtual base class declared 
here">;
 def err_constexpr_non_literal_return : Error<
-  "%select{constexpr|consteval}0 function's return type %1 is not a literal 
type">;
+  "%select{constexpr|consteval}0 function with non-literal return type %1 is a 
C++23 extension">;

Fznamznon wrote:

oops, still learning. Removed.

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-05 Thread Aaron Ballman via cfe-commits


@@ -2809,10 +2813,13 @@ def note_non_literal_virtual_base : 
Note<"%select{struct|interface|class}0 "
   "with virtual base %plural{1:class|:classes}1 is not a literal type">;
 def note_constexpr_virtual_base_here : Note<"virtual base class declared 
here">;
 def err_constexpr_non_literal_return : Error<
-  "%select{constexpr|consteval}0 function's return type %1 is not a literal 
type">;
+  "%select{constexpr|consteval}0 function with non-literal return type %1 is a 
C++23 extension">;

AaronBallman wrote:

This should be reverted back to the original diagnostic wording; we no longer 
treat it as an extension.

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-05 Thread Aaron Ballman via cfe-commits


@@ -2774,9 +2774,13 @@ def err_constexpr_tag : Error<
 def err_constexpr_dtor : Error<
   "destructor cannot be declared %sub{select_constexpr_spec_kind}0">;
 def err_constexpr_dtor_subobject : Error<
-  "destructor cannot be declared %sub{select_constexpr_spec_kind}0 because "
+  "destructor cannot be declared %sub{select_constexpr_spec_kind}0 before 
C++23 because "
   "%select{data member %2|base class %3}1 does not have a "
   "constexpr destructor">;
+def warn_cxx20_compat_constexpr_dtor_subobject : Warning<

AaronBallman wrote:

We usually only issue the compat warnings in cases where we expose it as an 
extension in earlier modes, so I think this warning can go away.

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-05 Thread Aaron Ballman via cfe-commits


@@ -2809,10 +2813,13 @@ def note_non_literal_virtual_base : 
Note<"%select{struct|interface|class}0 "
   "with virtual base %plural{1:class|:classes}1 is not a literal type">;
 def note_constexpr_virtual_base_here : Note<"virtual base class declared 
here">;
 def err_constexpr_non_literal_return : Error<
-  "%select{constexpr|consteval}0 function's return type %1 is not a literal 
type">;
+  "%select{constexpr|consteval}0 function with non-literal return type %1 is a 
C++23 extension">;
+def warn_cxx20_compat_constexpr_non_literal_return : Warning<
+  "%select{constexpr|consteval}0 function with non-literal return type %1 is 
incompatible with C++ standards before C++23">, InGroup, 
DefaultIgnore;
 def err_constexpr_non_literal_param : Error<
-  "%select{constexpr|consteval}2 %select{function|constructor}1's %ordinal0 
parameter type %3 is "
-  "not a literal type">;
+  "%select{constexpr|consteval}2 %select{function|constructor}1 with %ordinal0 
non-literal parameter type %3 is a C++23 extension">;

AaronBallman wrote:

This should be reverted to the original wording as well.

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-05 Thread Aaron Ballman via cfe-commits


@@ -2809,10 +2813,13 @@ def note_non_literal_virtual_base : 
Note<"%select{struct|interface|class}0 "
   "with virtual base %plural{1:class|:classes}1 is not a literal type">;
 def note_constexpr_virtual_base_here : Note<"virtual base class declared 
here">;
 def err_constexpr_non_literal_return : Error<
-  "%select{constexpr|consteval}0 function's return type %1 is not a literal 
type">;
+  "%select{constexpr|consteval}0 function with non-literal return type %1 is a 
C++23 extension">;
+def warn_cxx20_compat_constexpr_non_literal_return : Warning<

AaronBallman wrote:

This warning can be removed.

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-05 Thread Aaron Ballman via cfe-commits


@@ -2809,10 +2813,13 @@ def note_non_literal_virtual_base : 
Note<"%select{struct|interface|class}0 "
   "with virtual base %plural{1:class|:classes}1 is not a literal type">;
 def note_constexpr_virtual_base_here : Note<"virtual base class declared 
here">;
 def err_constexpr_non_literal_return : Error<
-  "%select{constexpr|consteval}0 function's return type %1 is not a literal 
type">;
+  "%select{constexpr|consteval}0 function with non-literal return type %1 is a 
C++23 extension">;
+def warn_cxx20_compat_constexpr_non_literal_return : Warning<
+  "%select{constexpr|consteval}0 function with non-literal return type %1 is 
incompatible with C++ standards before C++23">, InGroup, 
DefaultIgnore;
 def err_constexpr_non_literal_param : Error<
-  "%select{constexpr|consteval}2 %select{function|constructor}1's %ordinal0 
parameter type %3 is "
-  "not a literal type">;
+  "%select{constexpr|consteval}2 %select{function|constructor}1 with %ordinal0 
non-literal parameter type %3 is a C++23 extension">;
+def warn_cxx20_compat_constexpr_non_literal_param : Warning<

AaronBallman wrote:

This one can also go away.

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-05 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman edited 
https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-05 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman commented:

I found some possible changes to be made to the diagnostics.

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-05 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

Okay then, could you please review or give me an LGTM if everything is ok? The 
patch transformed a bit since it was first approved. It doesn't enable feature 
as extension now, it incorporates changes and test highlighted by 
https://github.com/llvm/llvm-project/pull/77753#issuecomment-1899137960 and I 
renamed diagnostic messages according to other similar ones.

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-05 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> We can enable it as an extension in older language modes later as a separate 
> patch in case there is user's demand on this. @cor3ntin , @AaronBallman 
> please let me know what you think.

Thank you for investigating this! I'm perfectly fine not enabling this as an 
extension in older language modes until we have a strong enough need to justify 
the efforts.

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-05 Thread Mariya Podchishchaeva via cfe-commits


@@ -356,14 +356,7 @@ C++23 implementation status
 
   Relaxing some constexpr restrictions
   https://wg21.link/P2448R2";>P2448R2
-  
-Clang 17 (Partial)
- We do not support outside of defaulted special memeber functions the 
change that constexpr functions no
-  longer have to be constexpr compatible but rather support a less 
restricted requirements for constexpr
-  functions. Which include allowing non-literal types as return values 
and parameters, allow calling of
-  non-constexpr functions and constructors.
-
-  
+  Clang 18

Fznamznon wrote:

```suggestion
  Clang 19
```

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-05 Thread Mariya Podchishchaeva via cfe-commits


@@ -9108,7 +9123,8 @@ bool Sema::CheckExplicitlyDefaultedComparison(Scope *S, 
FunctionDecl *FD,
   //   declaration, it is implicitly considered to be constexpr.
   // FIXME: Only applying this to the first declaration seems problematic, as
   // simple reorderings can affect the meaning of the program.
-  if (First && !FD->isConstexpr() && Info.Constexpr)
+  if ((First && !FD->isConstexpr() && Info.Constexpr) ||
+  getLangOpts().CPlusPlus23)

Fznamznon wrote:

I'm not sure actually that this change is required.
If the function is marked constexpr then we're all set here.
If the function is not explicitly marked constexpr, we could force it constexpr 
for c++23, but it is already done if it is Info.Constexpr is true. 
If Info.Constexpr is false it means that the function is constexpr only in 
c++23 and it means it can't be called from real constexpr
context anyway, additionally marking it constexpr doesn't lift more errors.
The point of p2448r2 here is that we can attach constexpr explicitly to it.

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-05 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

So, I've spent some time on it, and it turns out that because of current design 
choices supporting the whole feature in older language modes and not loosing 
any warnings/errors happens to be a much more significant change.
For example, due to the fact that constexprness of constructor/destructor can 
actually affect whether a class literal or not, to not loose any warnings it 
would require somehow preserve the info that a class is literal before and 
after c++23. The same actually works for each constructor/destructor 
declarations, now they would have to know not only whether they are constexpr, 
but whether they are constexpr before C++23, since bc of C++23 changes a number 
of implicit declarations became constexpr. Having this info only in parent 
class declaration is not enough, since at some point for each implicit member a 
`cxxconstructordecl` is created, and it can be later queried whether it is 
constexpr or not.
We can enable it as an extension in older language modes later as a separate 
patch in case there is user's demand on this.
@cor3ntin , @AaronBallman please let me know what you think.

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[flang] [libc] [lldb] [compiler-rt] [llvm] [clang-tools-extra] [libcxx] [lld] [clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-24 Thread Mariya Podchishchaeva via cfe-commits


@@ -9108,7 +9123,8 @@ bool Sema::CheckExplicitlyDefaultedComparison(Scope *S, 
FunctionDecl *FD,
   //   declaration, it is implicitly considered to be constexpr.
   // FIXME: Only applying this to the first declaration seems problematic, as
   // simple reorderings can affect the meaning of the program.
-  if (First && !FD->isConstexpr() && Info.Constexpr)
+  if ((First && !FD->isConstexpr() && Info.Constexpr) ||
+  getLangOpts().CPlusPlus23)

Fznamznon wrote:

This change perhaps needs a test.

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[flang] [libc] [lldb] [compiler-rt] [llvm] [clang-tools-extra] [libcxx] [lld] [clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-24 Thread Mariya Podchishchaeva via cfe-commits


@@ -356,14 +356,7 @@ C++23 implementation status
 
   Relaxing some constexpr restrictions
   https://wg21.link/P2448R2";>P2448R2
-  
-Clang 17 (Partial)
- We do not support outside of defaulted special memeber functions the 
change that constexpr functions no
-  longer have to be constexpr compatible but rather support a less 
restricted requirements for constexpr
-  functions. Which include allowing non-literal types as return values 
and parameters, allow calling of
-  non-constexpr functions and constructors.
-
-  
+  Clang 18

Fznamznon wrote:

I suppose, I should put clang 19 here, right?

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [llvm] [clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-18 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman approved this pull request.

Other than the one diagnostic concern, the changes LGTM and I think are fine 
for Clang 18.

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang-tools-extra] [clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-18 Thread Aaron Ballman via cfe-commits


@@ -2765,10 +2765,14 @@ def err_constexpr_tag : Error<
   "cannot be marked %sub{select_constexpr_spec_kind}1">;
 def err_constexpr_dtor : Error<
   "destructor cannot be declared %sub{select_constexpr_spec_kind}0">;
-def err_constexpr_dtor_subobject : Error<
-  "destructor cannot be declared %sub{select_constexpr_spec_kind}0 because "
+def ext_constexpr_dtor_subobject : ExtWarn<
+  "destructor cannot be declared %sub{select_constexpr_spec_kind}0 before 
C++23 because "
   "%select{data member %2|base class %3}1 does not have a "
-  "constexpr destructor">;
+  "constexpr destructor">, InGroup, DefaultError;
+def warn_cxx23_compat_constexpr_dtor_subobject : ExtWarn<

AaronBallman wrote:

```suggestion
def warn_cxx23_compat_constexpr_dtor_subobject : Warning<
```
this part isn't an extension, just a regular warning.

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang-tools-extra] [clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-17 Thread via cfe-commits


@@ -1731,11 +1731,7 @@ static bool CheckConstexprDestructorSubobjects(Sema 
&SemaRef,
   SemaRef.Diag(Loc, diag::note_constexpr_dtor_subobject)
   << !FD << (FD ? FD->getDeclName() : DeclarationName()) << T;
 }
-
-if (SemaRef.getLangOpts().CPlusPlus23)
-  return true;
-
-return false;
+return !!SemaRef.getLangOpts().CPlusPlus23;

cor3ntin wrote:

i missed the lambda sorry. Looks fine (alternatively `-> bool` might be just as 
clean)

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang-tools-extra] [clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-17 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon edited 
https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-17 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon edited 
https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-17 Thread Mariya Podchishchaeva via cfe-commits


@@ -1731,11 +1731,7 @@ static bool CheckConstexprDestructorSubobjects(Sema 
&SemaRef,
   SemaRef.Diag(Loc, diag::note_constexpr_dtor_subobject)
   << !FD << (FD ? FD->getDeclName() : DeclarationName()) << T;
 }
-
-if (SemaRef.getLangOpts().CPlusPlus23)
-  return true;
-
-return false;
+return !!SemaRef.getLangOpts().CPlusPlus23;

Fznamznon wrote:

It doesn't let me do so because lambda has deduced type and 
`SemaRef.getLangOpts().CPlusPlus23` is an `int` but intended return type is 
`bool`. `!!` is a dirty hack to convert to bool then return the right value.

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-17 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon edited 
https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-17 Thread Mariya Podchishchaeva via cfe-commits


@@ -165,6 +165,8 @@ C++23 Feature Support
 - Added a separate warning to warn the use of attributes on lambdas as a C++23 
extension
   in previous language versions: ``-Wc++23-lambda-attributes``.
 
+- Implemented `P2448R2: Relaxing some constexpr restrictions 
`_.
+

Fznamznon wrote:

Okay, done. I'm not sure I updated `LanguageExtensions.rst`, please take a look.
I also added some testing for enabling extension in earlier language modes.

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-11 Thread via cfe-commits


@@ -1754,11 +1761,17 @@ static bool CheckConstexprParameterTypes(Sema &SemaRef,
 const ParmVarDecl *PD = FD->getParamDecl(ArgIndex);
 assert(PD && "null in a parameter list");
 SourceLocation ParamLoc = PD->getLocation();
-if (CheckLiteralType(SemaRef, Kind, ParamLoc, *i,
- diag::err_constexpr_non_literal_param, ArgIndex + 1,
- PD->getSourceRange(), isa(FD),
- FD->isConsteval()))
+if (CheckLiteralType(
+SemaRef, Kind, ParamLoc, *i,
+SemaRef.getLangOpts().CPlusPlus23
+? diag::warn_cxx23_compat_constexpr_non_literal_param
+: diag::ext_constexpr_non_literal_param,
+ArgIndex + 1, PD->getSourceRange(), isa(FD),
+FD->isConsteval())) {
+  if (SemaRef.getLangOpts().CPlusPlus23)
+return true;
   return false;
+}

cor3ntin wrote:

ditto

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-11 Thread via cfe-commits


@@ -165,6 +165,8 @@ C++23 Feature Support
 - Added a separate warning to warn the use of attributes on lambdas as a C++23 
extension
   in previous language versions: ``-Wc++23-lambda-attributes``.
 
+- Implemented `P2448R2: Relaxing some constexpr restrictions 
`_.
+

cor3ntin wrote:

Can you say that it is implemented as a conforming extension?
We probably should document it in `LanguageExtensions.rst`

The feature macro in clang was already bumped, so that doesn't need change

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-11 Thread via cfe-commits


@@ -1767,10 +1780,16 @@ static bool CheckConstexprParameterTypes(Sema &SemaRef,
 /// true. If not, produce a suitable diagnostic and return false.
 static bool CheckConstexprReturnType(Sema &SemaRef, const FunctionDecl *FD,
  Sema::CheckConstexprKind Kind) {
-  if (CheckLiteralType(SemaRef, Kind, FD->getLocation(), FD->getReturnType(),
-   diag::err_constexpr_non_literal_return,
-   FD->isConsteval()))
+  if (CheckLiteralType(
+  SemaRef, Kind, FD->getLocation(), FD->getReturnType(),
+  SemaRef.getLangOpts().CPlusPlus23
+  ? diag::warn_cxx23_compat_constexpr_non_literal_return
+  : diag::ext_constexpr_non_literal_return,
+  FD->isConsteval())) {
+if (SemaRef.getLangOpts().CPlusPlus23)
+  return true;
 return false;
+  }

cor3ntin wrote:

ditto

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-11 Thread via cfe-commits


@@ -1722,12 +1722,19 @@ static bool CheckConstexprDestructorSubobjects(Sema 
&SemaRef,
   return true;
 
 if (Kind == Sema::CheckConstexprKind::Diagnose) {
-  SemaRef.Diag(DD->getLocation(), diag::err_constexpr_dtor_subobject)
+  SemaRef.Diag(DD->getLocation(),
+   SemaRef.getLangOpts().CPlusPlus23
+   ? diag::warn_cxx23_compat_constexpr_dtor_subobject
+   : diag::ext_constexpr_dtor_subobject)
   << static_cast(DD->getConstexprKind()) << !FD
   << (FD ? FD->getDeclName() : DeclarationName()) << T;
   SemaRef.Diag(Loc, diag::note_constexpr_dtor_subobject)
   << !FD << (FD ? FD->getDeclName() : DeclarationName()) << T;
 }
+
+if (SemaRef.getLangOpts().CPlusPlus23)
+  return true;
+
 return false;

cor3ntin wrote:

```suggestion
return SemaRef.getLangOpts().CPlusPlus23;
```

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-11 Thread via cfe-commits

https://github.com/cor3ntin edited 
https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-11 Thread via cfe-commits

https://github.com/cor3ntin commented:

Overall, I think this looks good.
Afaict the whole paper is implemented.

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-11 Thread Mariya Podchishchaeva via cfe-commits


@@ -423,13 +423,13 @@ namespace dr1359 { // dr1359: 3.5
 #if __cplusplus >= 201103L
   union A { constexpr A() = default; };
   union B { constexpr B() = default; int a; }; // #dr1359-B
-  // cxx11-17-error@-1 {{defaulted definition of default constructor is not 
constexpr}}
+  // cxx11-17-error@-1 {{defaulted definition of default constructor that 
marked constexpr but never produces a constant expression is a C++23 extension}}

Fznamznon wrote:

Same, In C++20 mode such constructor is considered as a valid and producing 
constexpr due to 
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1331r2.pdf , so no 
extension warning there.

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-11 Thread Mariya Podchishchaeva via cfe-commits


@@ -153,16 +153,16 @@ namespace dr1460 { // dr1460: 3.5
   namespace Defaulted {
 union A { constexpr A() = default; };
 union B { int n; constexpr B() = default; };
-// cxx11-17-error@-1 {{defaulted definition of default constructor is not 
constexpr}}
+// cxx11-17-error@-1 {{defaulted definition of default constructor that 
marked constexpr but never produces a constant expression is a C++23 extension}}

Fznamznon wrote:

In C++20 mode such constructor is considered as a valid and producing 
`constexpr` due to 
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1331r2.pdf , so no 
extension warning there.

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-11 Thread Vlad Serebrennikov via cfe-commits


@@ -349,8 +349,8 @@ namespace dr1684 { // dr1684: 3.6
   };
   constexpr int f(NonLiteral &) { return 0; }
   constexpr int f(NonLiteral) { return 0; }
-  // since-cxx11-error@-1 {{constexpr function's 1st parameter type 
'NonLiteral' is not a literal type}}
-  //   since-cxx11-note@#dr1684-struct {{'NonLiteral' is not literal because 
it is not an aggregate and has no constexpr constructors other than copy or 
move constructors}}
+  // cxx11-20-error@-1 {{constexpr function with 1st non-literal parameter 
type 'NonLiteral' is a C++23 extension}}
+  // cxx11-20-note@#dr1684-struct {{'NonLiteral' is not literal because it is 
not an aggregate and has no constexpr constructors other than copy or move 
constructors}}

Endilll wrote:

```suggestion
  //   cxx11-20-note@#dr1684-struct {{'NonLiteral' is not literal because it is 
not an aggregate and has no constexpr constructors other than copy or move 
constructors}}
```

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-11 Thread Vlad Serebrennikov via cfe-commits


@@ -410,11 +410,11 @@ namespace dr1358 { // dr1358: 3.1
   struct B : Virt {
 int member;
 constexpr B(NonLit u) : member(u) {}
-// since-cxx11-error@-1 {{constexpr constructor's 1st parameter type 
'NonLit' is not a literal type}}
-//   since-cxx11-note@#dr1358-NonLit {{'NonLit' is not literal because it 
is not an aggregate and has no constexpr constructors other than copy or move 
constructors}}
+// cxx11-20-error@-1 {{constexpr constructor with 1st non-literal 
parameter type 'NonLit' is a C++23 extension}}
+// cxx11-20-note@#dr1358-NonLit {{'NonLit' is not literal because it is 
not an aggregate and has no constexpr constructors other than copy or move 
constructors}}

Endilll wrote:

```suggestion
//   cxx11-20-note@#dr1358-NonLit {{'NonLit' is not literal because it is 
not an aggregate and has no constexpr constructors other than copy or move 
constructors}}
```

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-11 Thread Vlad Serebrennikov via cfe-commits


@@ -423,13 +423,13 @@ namespace dr1359 { // dr1359: 3.5
 #if __cplusplus >= 201103L
   union A { constexpr A() = default; };
   union B { constexpr B() = default; int a; }; // #dr1359-B
-  // cxx11-17-error@-1 {{defaulted definition of default constructor is not 
constexpr}}
+  // cxx11-17-error@-1 {{defaulted definition of default constructor that 
marked constexpr but never produces a constant expression is a C++23 extension}}

Endilll wrote:

11 through 17 we expect a 23 extension warning, but what happens in 20 mode?

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-11 Thread Vlad Serebrennikov via cfe-commits


@@ -584,8 +584,8 @@ namespace dr647 { // dr647: 3.1
   struct C {
 constexpr C(NonLiteral);
 constexpr C(NonLiteral, int) {}
-// since-cxx11-error@-1 {{constexpr constructor's 1st parameter type 
'NonLiteral' is not a literal type}}
-//   since-cxx11-note@#dr647-NonLiteral {{'NonLiteral' is not literal 
because it is not an aggregate and has no constexpr constructors other than 
copy or move constructors}}
+// cxx11-20-error@-1 {{constexpr constructor with 1st non-literal 
parameter type 'NonLiteral' is a C++23 extension}}
+// cxx11-20-note@#dr647-NonLiteral {{'NonLiteral' is not literal because 
it is not an aggregate and has no constexpr constructors other than copy or 
move constructors}}

Endilll wrote:

```suggestion
//   cxx11-20-note@#dr647-NonLiteral {{'NonLiteral' is not literal because 
it is not an aggregate and has no constexpr constructors other than copy or 
move constructors}}
```

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-11 Thread Vlad Serebrennikov via cfe-commits


@@ -410,11 +410,11 @@ namespace dr1358 { // dr1358: 3.1
   struct B : Virt {
 int member;
 constexpr B(NonLit u) : member(u) {}
-// since-cxx11-error@-1 {{constexpr constructor's 1st parameter type 
'NonLit' is not a literal type}}
-//   since-cxx11-note@#dr1358-NonLit {{'NonLit' is not literal because it 
is not an aggregate and has no constexpr constructors other than copy or move 
constructors}}
+// cxx11-20-error@-1 {{constexpr constructor with 1st non-literal 
parameter type 'NonLit' is a C++23 extension}}
+// cxx11-20-note@#dr1358-NonLit {{'NonLit' is not literal because it is 
not an aggregate and has no constexpr constructors other than copy or move 
constructors}}
 constexpr NonLit f(NonLit u) const { return NonLit(); }
-// since-cxx11-error@-1 {{constexpr function's return type 'NonLit' is not 
a literal type}}
-//   since-cxx11-note@#dr1358-NonLit {{'NonLit' is not literal because it 
is not an aggregate and has no constexpr constructors other than copy or move 
constructors}}
+// cxx11-20-error@-1 {{constexpr function with non-literal return type 
'NonLit' is a C++23 extension}}
+// cxx11-20-note@#dr1358-NonLit {{'NonLit' is not literal because it is 
not an aggregate and has no constexpr constructors other than copy or move 
constructors}}

Endilll wrote:

```suggestion
//   cxx11-20-note@#dr1358-NonLit {{'NonLit' is not literal because it is 
not an aggregate and has no constexpr constructors other than copy or move 
constructors}}
```

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-11 Thread Vlad Serebrennikov via cfe-commits


@@ -153,16 +153,16 @@ namespace dr1460 { // dr1460: 3.5
   namespace Defaulted {
 union A { constexpr A() = default; };
 union B { int n; constexpr B() = default; };
-// cxx11-17-error@-1 {{defaulted definition of default constructor is not 
constexpr}}
+// cxx11-17-error@-1 {{defaulted definition of default constructor that 
marked constexpr but never produces a constant expression is a C++23 extension}}

Endilll wrote:

11 through 17 we expect a 23 extension warning, but what happens in 20 mode?

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-11 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll edited 
https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-11 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll commented:

I checked changes to DR tests, as that's the only part of this PR I'm competent 
enough for.

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-11 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff dc974573a8a2364f24ce69c75ad80ab30753fe9a 
699f47bba02012523e1862f9b15ce9de1d7511b5 -- 
clang/test/SemaCXX/cxx23-invalid-constexpr.cpp clang/lib/Sema/SemaDeclCXX.cpp 
clang/test/AST/Interp/cxx23.cpp clang/test/AST/Interp/literals.cpp 
clang/test/AST/Interp/shifts.cpp clang/test/CXX/basic/basic.types/p10.cpp 
clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/dtor.cpp 
clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3-2b.cpp 
clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp 
clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp 
clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p5.cpp 
clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p6.cpp 
clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp 
clang/test/CXX/drs/dr13xx.cpp clang/test/CXX/drs/dr14xx.cpp 
clang/test/CXX/drs/dr16xx.cpp clang/test/CXX/drs/dr6xx.cpp 
clang/test/CXX/expr/expr.const/p2-0x.cpp 
clang/test/CXX/expr/expr.const/p5-26.cpp 
clang/test/CXX/special/class.copy/p13-0x.cpp clang/test/PCH/cxx11-constexpr.cpp 
clang/test/SemaCXX/builtin_vectorelements.cpp 
clang/test/SemaCXX/constant-expression-cxx11.cpp 
clang/test/SemaCXX/constant-expression-cxx14.cpp 
clang/test/SemaCXX/constant-expression-cxx2b.cpp 
clang/test/SemaCXX/constexpr-function-recovery-crash.cpp 
clang/test/SemaCXX/cxx1z-constexpr-lambdas.cpp 
clang/test/SemaCXX/cxx2a-consteval.cpp 
clang/test/SemaCXX/deduced-return-type-cxx14.cpp 
clang/test/SemaCXX/ms-constexpr-invalid.cpp clang/test/SemaCXX/ms-constexpr.cpp 
clang/test/SemaCXX/sizeless-1.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index aa49dc73e1..20c8c3ef6c 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -7881,8 +7881,8 @@ bool 
Sema::CheckExplicitlyDefaultedSpecialMember(CXXMethodDecl *MD,
   << CSM << MD->isConsteval();
 }
 // FIXME: Explain why the special member can't be constexpr.
-if (!getLangOpts().CPlusPlus23)
-  HadError = true;
+if (!getLangOpts().CPlusPlus23)
+  HadError = true;
   }
 
   if (First) {

``




https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Mariya Podchishchaeva (Fznamznon)


Changes

Per https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2448r2.html 
function/constructor/destructor can be marked `constexpr` even though it never 
produces a constant expression.
Non-literal types as return types and parameter types of functions marked 
`constexpr` are also allowed.
Since this is not a DR, the diagnostic messages are still preserved for C++ 
standards older than C++23.

---

Patch is 88.09 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/77753.diff


36 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+26-16) 
- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+39-15) 
- (modified) clang/test/AST/Interp/cxx23.cpp (+6-18) 
- (modified) clang/test/AST/Interp/literals.cpp (+1-1) 
- (modified) clang/test/AST/Interp/shifts.cpp (+4-4) 
- (modified) clang/test/CXX/basic/basic.types/p10.cpp (+13-13) 
- (modified) clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/dtor.cpp (+4-4) 
- (modified) clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3-2b.cpp (+2-2) 
- (modified) clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp (+13-14) 
- (modified) clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp (+10-10) 
- (modified) clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p5.cpp (+3-3) 
- (modified) clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p6.cpp (+1-1) 
- (modified) clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp 
(+3-3) 
- (modified) clang/test/CXX/drs/dr13xx.cpp (+11-11) 
- (modified) clang/test/CXX/drs/dr14xx.cpp (+3-3) 
- (modified) clang/test/CXX/drs/dr16xx.cpp (+6-6) 
- (modified) clang/test/CXX/drs/dr6xx.cpp (+12-12) 
- (modified) clang/test/CXX/expr/expr.const/p2-0x.cpp (+1-1) 
- (modified) clang/test/CXX/expr/expr.const/p5-26.cpp (+2-2) 
- (modified) clang/test/CXX/special/class.copy/p13-0x.cpp (+1-1) 
- (modified) clang/test/PCH/cxx11-constexpr.cpp (+1-1) 
- (modified) clang/test/SemaCXX/builtin_vectorelements.cpp (+1-1) 
- (modified) clang/test/SemaCXX/constant-expression-cxx11.cpp (+15-14) 
- (modified) clang/test/SemaCXX/constant-expression-cxx14.cpp (+17-16) 
- (modified) clang/test/SemaCXX/constant-expression-cxx2b.cpp (+12-6) 
- (modified) clang/test/SemaCXX/constexpr-function-recovery-crash.cpp (+2-2) 
- (modified) clang/test/SemaCXX/cxx1z-constexpr-lambdas.cpp (+2-2) 
- (added) clang/test/SemaCXX/cxx23-invalid-constexpr.cpp (+152) 
- (modified) clang/test/SemaCXX/cxx2a-consteval.cpp (+2-2) 
- (modified) clang/test/SemaCXX/deduced-return-type-cxx14.cpp (+4-4) 
- (modified) clang/test/SemaCXX/ms-constexpr-invalid.cpp (+3-3) 
- (modified) clang/test/SemaCXX/ms-constexpr.cpp (+1-1) 
- (modified) clang/test/SemaCXX/sizeless-1.cpp (+1-1) 
- (modified) clang/test/SemaOpenCLCXX/addrspace-constructors.clcpp (+1-1) 
- (modified) clang/www/cxx_status.html (+1-8) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a18d36a16b1a9c..23342a6a7256d8 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -165,6 +165,8 @@ C++23 Feature Support
 - Added a separate warning to warn the use of attributes on lambdas as a C++23 
extension
   in previous language versions: ``-Wc++23-lambda-attributes``.
 
+- Implemented `P2448R2: Relaxing some constexpr restrictions 
`_.
+
 C++2c Feature Support
 ^
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 1a79892e40030a..67409374f26dfa 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2765,10 +2765,14 @@ def err_constexpr_tag : Error<
   "cannot be marked %sub{select_constexpr_spec_kind}1">;
 def err_constexpr_dtor : Error<
   "destructor cannot be declared %sub{select_constexpr_spec_kind}0">;
-def err_constexpr_dtor_subobject : Error<
-  "destructor cannot be declared %sub{select_constexpr_spec_kind}0 because "
+def ext_constexpr_dtor_subobject : ExtWarn<
+  "destructor cannot be declared %sub{select_constexpr_spec_kind}0 before 
C++23 because "
   "%select{data member %2|base class %3}1 does not have a "
-  "constexpr destructor">;
+  "constexpr destructor">, InGroup, DefaultError;
+def warn_cxx23_compat_constexpr_dtor_subobject : ExtWarn<
+  "%sub{select_constexpr_spec_kind}0 destructor is incompatible with C++ 
standards before C++23 because "
+  "%select{data member %2|base class %3}1 does not have a "
+  "constexpr destructor">, InGroup, DefaultIgnore;
 def note_constexpr_dtor_subobject : Note<
   "%select{data member %1|base class %2}0 declared here">;
 def err_constexpr_wrong_decl_kind : Error<
@@ -2800,11 +2804,14 @@ def note_non_literal_incomplete : Note<
 def note_non_literal_virtual_base : Note<"%select{struct|interface|class}0 "
   "with virtual base %plural{1:class|:classe

[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-11 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon created 
https://github.com/llvm/llvm-project/pull/77753

Per https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2448r2.html 
function/constructor/destructor can be marked `constexpr` even though it never 
produces a constant expression.
Non-literal types as return types and parameter types of functions marked 
`constexpr` are also allowed.
Since this is not a DR, the diagnostic messages are still preserved for C++ 
standards older than C++23.

>From 699f47bba02012523e1862f9b15ce9de1d7511b5 Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Wed, 18 Oct 2023 02:47:33 -0700
Subject: [PATCH] [Clang][C++23] Implement P2448R2: Relaxing some constexpr
 restrictions

Per https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2448r2.html
function/constructor/destructor can be marked `constexpr` even though it never
produces a constant expression.
Non-literal types as return types and parameter types of functions
marked `constexpr` are also allowed.
Since this is not a DR, the diagnostic messages are still preserved for
C++ standards older than C++23.
---
 clang/docs/ReleaseNotes.rst   |   2 +
 .../clang/Basic/DiagnosticSemaKinds.td|  42 +++--
 clang/lib/Sema/SemaDeclCXX.cpp|  54 +--
 clang/test/AST/Interp/cxx23.cpp   |  24 +--
 clang/test/AST/Interp/literals.cpp|   2 +-
 clang/test/AST/Interp/shifts.cpp  |   8 +-
 clang/test/CXX/basic/basic.types/p10.cpp  |  26 +--
 .../dcl.dcl/dcl.spec/dcl.constexpr/dtor.cpp   |   8 +-
 .../dcl.dcl/dcl.spec/dcl.constexpr/p3-2b.cpp  |   4 +-
 .../CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp |  27 ++--
 .../CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp |  20 +--
 .../CXX/dcl.dcl/dcl.spec/dcl.constexpr/p5.cpp |   6 +-
 .../CXX/dcl.dcl/dcl.spec/dcl.constexpr/p6.cpp |   2 +-
 .../dcl.fct.def/dcl.fct.def.default/p2.cpp|   6 +-
 clang/test/CXX/drs/dr13xx.cpp |  22 +--
 clang/test/CXX/drs/dr14xx.cpp |   6 +-
 clang/test/CXX/drs/dr16xx.cpp |  12 +-
 clang/test/CXX/drs/dr6xx.cpp  |  24 +--
 clang/test/CXX/expr/expr.const/p2-0x.cpp  |   2 +-
 clang/test/CXX/expr/expr.const/p5-26.cpp  |   4 +-
 clang/test/CXX/special/class.copy/p13-0x.cpp  |   2 +-
 clang/test/PCH/cxx11-constexpr.cpp|   2 +-
 clang/test/SemaCXX/builtin_vectorelements.cpp |   2 +-
 .../SemaCXX/constant-expression-cxx11.cpp |  29 ++--
 .../SemaCXX/constant-expression-cxx14.cpp |  33 ++--
 .../SemaCXX/constant-expression-cxx2b.cpp |  18 ++-
 .../constexpr-function-recovery-crash.cpp |   4 +-
 .../test/SemaCXX/cxx1z-constexpr-lambdas.cpp  |   4 +-
 .../test/SemaCXX/cxx23-invalid-constexpr.cpp  | 152 ++
 clang/test/SemaCXX/cxx2a-consteval.cpp|   4 +-
 .../SemaCXX/deduced-return-type-cxx14.cpp |   8 +-
 clang/test/SemaCXX/ms-constexpr-invalid.cpp   |   6 +-
 clang/test/SemaCXX/ms-constexpr.cpp   |   2 +-
 clang/test/SemaCXX/sizeless-1.cpp |   2 +-
 .../addrspace-constructors.clcpp  |   2 +-
 clang/www/cxx_status.html |   9 +-
 36 files changed, 378 insertions(+), 202 deletions(-)
 create mode 100644 clang/test/SemaCXX/cxx23-invalid-constexpr.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a18d36a16b1a9c..23342a6a7256d8 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -165,6 +165,8 @@ C++23 Feature Support
 - Added a separate warning to warn the use of attributes on lambdas as a C++23 
extension
   in previous language versions: ``-Wc++23-lambda-attributes``.
 
+- Implemented `P2448R2: Relaxing some constexpr restrictions 
`_.
+
 C++2c Feature Support
 ^
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 1a79892e40030a..67409374f26dfa 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2765,10 +2765,14 @@ def err_constexpr_tag : Error<
   "cannot be marked %sub{select_constexpr_spec_kind}1">;
 def err_constexpr_dtor : Error<
   "destructor cannot be declared %sub{select_constexpr_spec_kind}0">;
-def err_constexpr_dtor_subobject : Error<
-  "destructor cannot be declared %sub{select_constexpr_spec_kind}0 because "
+def ext_constexpr_dtor_subobject : ExtWarn<
+  "destructor cannot be declared %sub{select_constexpr_spec_kind}0 before 
C++23 because "
   "%select{data member %2|base class %3}1 does not have a "
-  "constexpr destructor">;
+  "constexpr destructor">, InGroup, DefaultError;
+def warn_cxx23_compat_constexpr_dtor_subobject : ExtWarn<
+  "%sub{select_constexpr_spec_kind}0 destructor is incompatible with C++ 
standards before C++23 because "
+  "%select{data member %2|base class %3}1 does not have a "
+  "constexpr destructor">, InGroup, DefaultIgnore;
 def note_constexpr_