public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/94353] New: std::copy* breaks when one type is volatile
@ 2020-03-27  9:06 alex at grundis dot de
  2020-03-27  9:21 ` [Bug libstdc++/94353] " redi at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: alex at grundis dot de @ 2020-03-27  9:06 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94353

            Bug ID: 94353
           Summary: std::copy* breaks when one type is volatile
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: alex at grundis dot de
  Target Milestone: ---

The following code breaks:

    #include <algorithm>

    void foo(const char* b, volatile char* d){
        std::copy_n(b, 10, d);
    }

This is a regression from earlier versions where it worked fine. The reason is
that at some point `struct __copy_move<_IsMove, true,
random_access_iterator_tag>::__copy_m(const _Tp* __first, const _Tp* __last,
_Tp* __result)` is called where it fails to deduce `__Tp` because it is `char`
and `volatile char`

Full stack: 

In file included from /usr/local/include/c++/10.0.1/bits/char_traits.h:39,
                 from /usr/local/include/c++/10.0.1/string:40,
                 from /usr/local/include/c++/10.0.1/stdexcept:39,
                 from /usr/local/include/c++/10.0.1/system_error:41,
                 from
/home/jakecooke/Code/CPP/Glade/src/simulator/abseil-cpp/absl/strings/charconv.h:18,
                 from
/home/jakecooke/Code/CPP/Glade/src/simulator/abseil-cpp/absl/strings/charconv.cc:15:
/usr/local/include/c++/10.0.1/bits/stl_algobase.h: In instantiation of
'constexpr _OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove = false;
_II = const char*; _OI = volatile char*]':
/usr/local/include/c++/10.0.1/bits/stl_algobase.h:533:42:   required from
'constexpr _OI std::__copy_move_a1(_II, _II, _OI) [with bool _IsMove = false;
_II = const char*; _OI = volatile char*]'
/usr/local/include/c++/10.0.1/bits/stl_algobase.h:541:31:   required from
'constexpr _OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove = false;
_II = const char*; _OI = volatile char*]'
/usr/local/include/c++/10.0.1/bits/stl_algobase.h:596:7:   required from
'constexpr _OI std::copy(_II, _II, _OI) [with _II = const char*; _OI = volatile
char*]'
/usr/local/include/c++/10.0.1/bits/stl_algo.h:820:23:   required from
'constexpr _OutputIterator std::__copy_n(_RandomAccessIterator, _Size,
_OutputIterator, std::random_access_iterator_tag) [with _RandomAccessIterator =
const char*; _Size = long int; _OutputIterator = volatile char*]'
/usr/local/include/c++/10.0.1/bits/stl_algo.h:847:27:   required from
'constexpr _OIter std::copy_n(_IIter, _Size, _OIter) [with _IIter = const
char*; _Size = long int; _OIter = volatile char*]'
/home/jakecooke/Code/CPP/Glade/src/simulator/abseil-cpp/absl/strings/charconv.cc:301:7:
  required from 'bool absl::{anonymous}::HandleEdgeCase(const
absl::strings_internal::ParsedFloat&, bool, FloatType*) [with FloatType =
double]'
/home/jakecooke/Code/CPP/Glade/src/simulator/abseil-cpp/absl/strings/charconv.cc:636:23:
  required from 'absl::from_chars_result absl::{anonymous}::FromCharsImpl(const
char*, const char*, FloatType&, absl::chars_format) [with FloatType = double]'
/home/jakecooke/Code/CPP/Glade/src/simulator/abseil-cpp/absl/strings/charconv.cc:681:47:
  required from here
/usr/local/include/c++/10.0.1/bits/stl_algobase.h:499:30: error: no matching
function for call to 'std::__copy_move<false, true,
std::random_access_iterator_tag>::__copy_m(const char*&, const char*&, volatile
char*&)'
  498 |       return std::__copy_move<_IsMove, __simple,
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  499 |          _Category>::__copy_m(__first, __last, __result);
      |          ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/c++/10.0.1/bits/stl_algobase.h:441:2: note: candidate:
'template<class _Tp> static constexpr _Tp* std::__copy_move<_IsMove, true,
std::random_access_iterator_tag>::__copy_m(const _Tp*, const _Tp*, _Tp*) [with
_Tp = _Tp; bool _IsMove = false]'
  441 |  __copy_m(const _Tp* __first, const _Tp* __last, _Tp* __result)
      |  ^~~~~~~~
/usr/local/include/c++/10.0.1/bits/stl_algobase.h:441:2: note:   template
argument deduction/substitution failed:
/usr/local/include/c++/10.0.1/bits/stl_algobase.h:499:30: note:   deduced
conflicting types for parameter '_Tp' ('char' and 'volatile char')
  498 |       return std::__copy_move<_IsMove, __simple,
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  499 |          _Category>::__copy_m(__first, __last, __result);
      |          ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~


It seems that this should be fixed by
https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=462f6c2041fad058abcdd5122e99a024f69a39d5
because `__memcpyable<volatile char*, const char*>` should return false. But
there doesn't seem to be a test case for mixed volatile pointers. I'd suggest
to add them

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug libstdc++/94353] std::copy* breaks when one type is volatile
  2020-03-27  9:06 [Bug libstdc++/94353] New: std::copy* breaks when one type is volatile alex at grundis dot de
@ 2020-03-27  9:21 ` redi at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: redi at gcc dot gnu.org @ 2020-03-27  9:21 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94353

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
It is fixed by that commit, and there are several tests for mixed volatile
pointers e.g.

+  volatile int i[2] = { 1, 2 };
+  volatile int j[2] = { 0, 0 };
+  int k[2] = { 0, 0 };
+
+  std::copy(i, i+2, j);
+  VERIFY( j[0] == 1 && j[1] == 2 );
+  std::copy(i, i+2, k);
   ^^^^^^^^^^^^^^^^^^^^^

*** This bug has been marked as a duplicate of bug 94013 ***

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-03-27  9:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-27  9:06 [Bug libstdc++/94353] New: std::copy* breaks when one type is volatile alex at grundis dot de
2020-03-27  9:21 ` [Bug libstdc++/94353] " redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).