[Bug libstdc++/113200] std::char_traits::move is not constexpr when the argument is a string literal

2024-01-11 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113200

Jonathan Wakely  changed:

   What|Removed |Added

 Resolution|--- |FIXED
 Status|NEW |RESOLVED

--- Comment #13 from Jonathan Wakely  ---
Fixed for 12.4 and 13.3, thanks for the report.

[Bug libstdc++/113200] std::char_traits::move is not constexpr when the argument is a string literal

2024-01-11 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113200

--- Comment #12 from GCC Commits  ---
The releases/gcc-12 branch has been updated by Jonathan Wakely
:

https://gcc.gnu.org/g:26a9e8cee4d20e5b08c0336439c8f69a2f06af1c

commit r12-10090-g26a9e8cee4d20e5b08c0336439c8f69a2f06af1c
Author: Jonathan Wakely 
Date:   Wed Jan 3 15:01:09 2024 +

libstdc++: Fix std::char_traits::move [PR113200]

The current constexpr implementation of std::char_traits::move relies
on being able to compare the pointer parameters, which is not allowed
for unrelated pointers. We can use __builtin_constant_p to determine
whether it's safe to compare the pointers directly. If not, then we know
the ranges must be disjoint and so we can use char_traits::copy to
copy forwards from the first character to the last. If the pointers can
be compared directly, then we can simplify the condition for copying
backwards to just two pointer comparisons.

libstdc++-v3/ChangeLog:

PR libstdc++/113200
* include/bits/char_traits.h (__gnu_cxx::char_traits::move): Use
__builtin_constant_p to check for unrelated pointers that cannot
be compared during constant evaluation.
* testsuite/21_strings/char_traits/requirements/113200.cc: New
test.

(cherry picked from commit 15cc291887dc9dd92b2c93f4545e20eb6c190122)

[Bug libstdc++/113200] std::char_traits::move is not constexpr when the argument is a string literal

2024-01-06 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113200

--- Comment #11 from GCC Commits  ---
The releases/gcc-13 branch has been updated by Jonathan Wakely
:

https://gcc.gnu.org/g:22601c1c25652c71c8bab4707866c020d6dad79a

commit r13-8193-g22601c1c25652c71c8bab4707866c020d6dad79a
Author: Jonathan Wakely 
Date:   Wed Jan 3 15:01:09 2024 +

libstdc++: Fix std::char_traits::move [PR113200]

The current constexpr implementation of std::char_traits::move relies
on being able to compare the pointer parameters, which is not allowed
for unrelated pointers. We can use __builtin_constant_p to determine
whether it's safe to compare the pointers directly. If not, then we know
the ranges must be disjoint and so we can use char_traits::copy to
copy forwards from the first character to the last. If the pointers can
be compared directly, then we can simplify the condition for copying
backwards to just two pointer comparisons.

libstdc++-v3/ChangeLog:

PR libstdc++/113200
* include/bits/char_traits.h (__gnu_cxx::char_traits::move): Use
__builtin_constant_p to check for unrelated pointers that cannot
be compared during constant evaluation.
* testsuite/21_strings/char_traits/requirements/113200.cc: New
test.

(cherry picked from commit 15cc291887dc9dd92b2c93f4545e20eb6c190122)

[Bug libstdc++/113200] std::char_traits::move is not constexpr when the argument is a string literal

2024-01-05 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113200

Jonathan Wakely  changed:

   What|Removed |Added

   Target Milestone|--- |12.4

[Bug libstdc++/113200] std::char_traits::move is not constexpr when the argument is a string literal

2024-01-05 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113200

--- Comment #10 from GCC Commits  ---
The master branch has been updated by Jonathan Wakely :

https://gcc.gnu.org/g:15cc291887dc9dd92b2c93f4545e20eb6c190122

commit r14-6944-g15cc291887dc9dd92b2c93f4545e20eb6c190122
Author: Jonathan Wakely 
Date:   Wed Jan 3 15:01:09 2024 +

libstdc++: Fix std::char_traits::move [PR113200]

The current constexpr implementation of std::char_traits::move relies
on being able to compare the pointer parameters, which is not allowed
for unrelated pointers. We can use __builtin_constant_p to determine
whether it's safe to compare the pointers directly. If not, then we know
the ranges must be disjoint and so we can use char_traits::copy to
copy forwards from the first character to the last. If the pointers can
be compared directly, then we can simplify the condition for copying
backwards to just two pointer comparisons.

libstdc++-v3/ChangeLog:

PR libstdc++/113200
* include/bits/char_traits.h (__gnu_cxx::char_traits::move): Use
__builtin_constant_p to check for unrelated pointers that cannot
be compared during constant evaluation.
* testsuite/21_strings/char_traits/requirements/113200.cc: New
test.

[Bug libstdc++/113200] std::char_traits::move is not constexpr when the argument is a string literal

2024-01-03 Thread de34 at live dot cn via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113200

Jiang An  changed:

   What|Removed |Added

 CC||de34 at live dot cn

--- Comment #9 from Jiang An  ---
(In reply to Peter Dimov from comment #3)
> I think that the compiler is correct; string literal address comparisons
> aren't constant expressions. Clang gives the same error:
> https://godbolt.org/z/xPWEf4z63.

This looks weird... It seems that `+"abc" == +"def"` is never unspecified (must
be false, but Clang rejects it in constant evaluation), while `"abcd" + 1 ==
+"bcd"` is unspecified.

It's unclear to me whether we can practically detect all kinds of
unspecifiedness in pointer comparision involving string literals.

[Bug libstdc++/113200] std::char_traits::move is not constexpr when the argument is a string literal

2024-01-03 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113200

--- Comment #8 from Jonathan Wakely  ---
(In reply to Jonathan Wakely from comment #7)
> Why does GCC accept this reduced version, which is invalid for the same
> reason as the original?

Looks like PR 70248

[Bug libstdc++/113200] std::char_traits::move is not constexpr when the argument is a string literal

2024-01-03 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113200

--- Comment #7 from Jonathan Wakely  ---
Why does GCC accept this reduced version, which is invalid for the same reason
as the original?

#include 

constexpr int N = 5;
struct S
{
char data_[ N ];

constexpr S( char const* p )
{
std::char_traits::move( data_, p, N );
}
};

constexpr S s( "test" );


Clang rejects it the same way.

[Bug libstdc++/113200] std::char_traits::move is not constexpr when the argument is a string literal

2024-01-03 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113200

Jonathan Wakely  changed:

   What|Removed |Added

  Component|c++ |libstdc++
   Keywords|diagnostic  |rejects-valid

--- Comment #6 from Jonathan Wakely  ---
Although we should fix the libstdc++ problem first, then re-assign (or maybe
file a separate bug for the FE diagnostic).

[Bug libstdc++/113200] std::char_traits::move is not constexpr when the argument is a string literal

2024-01-02 Thread pdimov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113200

--- Comment #4 from Peter Dimov  ---
I didn't notice your subsequent comment, sorry. :-)

[Bug libstdc++/113200] std::char_traits::move is not constexpr when the argument is a string literal

2024-01-02 Thread pdimov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113200

--- Comment #3 from Peter Dimov  ---
I think that the compiler is correct; string literal address comparisons aren't
constant expressions. Clang gives the same error:
https://godbolt.org/z/xPWEf4z63.

[Bug libstdc++/113200] std::char_traits::move is not constexpr when the argument is a string literal

2024-01-02 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113200

Andrew Pinski  changed:

   What|Removed |Added

  Component|c++ |libstdc++

--- Comment #2 from Andrew Pinski  ---
I take that back, clang provideds a better error message on why `&a ==
"string"` is not constexpr:

```
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/14.0.0/../../../../include/c++/14.0.0/bits/char_traits.h:230:13:
note: comparison of addresses of literals has unspecified value
  230 |   if (__s1 == __s2) // unlikely, but saves a lot of work
  |^
```