public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/94869] New: Template argument deduction/substitution failure with Howard Hinnant's calendar library
@ 2020-04-30  8:18 lcarreon at bigpond dot net.au
  2020-04-30  9:11 ` [Bug libstdc++/94869] [10 Regression] " rguenth at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: lcarreon at bigpond dot net.au @ 2020-04-30  8:18 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 94869
           Summary: Template argument deduction/substitution failure with
                    Howard Hinnant's calendar library
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lcarreon at bigpond dot net.au
  Target Milestone: ---

The following bit of code used to compile ok with g++ 9.2.1.

#include <date.h>

int main()
{
    std::istringstream str{"2020-04-30 17:30:00.000"}; 
    std::chrono::local_time<std::chrono::milliseconds> loc_time;
    str >> date::parse("%Y-%m-%d %H:%M:%S", loc_time);
    return 0;
}

(NOTE: date.h is Howard Hinnant's sample implementation of the calendar library
included in C++20.)

However, when I compile with g++ 10.0.1 using this command line:

g++ -c -g -m64 -O3 -Wall -Werror -I/usr/local/include -std=c++2a dt.cpp

The compile fails with the following messages (excerpt only/incomplete):

dt.cpp:7:50: error: no matching function for call to ‘parse(const char [18],
std::chrono::local_time<std::chrono::duration<long int, std::ratio<1, 1000> >
>&)’
    7 |  str >> date::parse("%Y-%m-%d %H:%M:%S", loc_time);
      |                                                  ^
In file included from dt.cpp:1:
/usr/local/include/date.h:7827:1: note: candidate: ‘template<class Parsable,
class CharT, class Traits, class Alloc> decltype
((date::from_stream(declval<std::basic_istream<_CharT, _Traits>&>(),
format.c_str(), tp), date::parse_manip<Parsable, CharT, Traits, Alloc>{format,
tp})) date::parse(const std::__cxx11::basic_string<CharT, Traits, Alloc>&,
Parsable&)’
 7827 | parse(const std::basic_string<CharT, Traits, Alloc>& format, Parsable&
tp)
      | ^~~~~
/usr/local/include/date.h:7827:1: note:   template argument
deduction/substitution failed:
dt.cpp:7:50: note:   mismatched types ‘const std::__cxx11::basic_string<CharT,
Traits, Alloc>’ and ‘const char [18]’
    7 |  str >> date::parse("%Y-%m-%d %H:%M:%S", loc_time);
      |                                                  ^
In file included from dt.cpp:1:
/usr/local/include/date.h:7838:1: note: candidate: ‘template<class Parsable,
class CharT, class Traits, class Alloc> decltype
((date::from_stream(declval<std::basic_istream<_CharT, _Traits>&>(),
format.c_str(), tp, (& abbrev)), date::parse_manip<Parsable, CharT, Traits,
Alloc>{format, tp, (& abbrev)})) date::parse(const
std::__cxx11::basic_string<CharT, Traits, Alloc>&, Parsable&,
std::__cxx11::basic_string<CharT, Traits, Alloc>&)’
 7838 | parse(const std::basic_string<CharT, Traits, Alloc>& format, Parsable&
tp,
      | ^~~~~
/usr/local/include/date.h:7838:1: note:   template argument
deduction/substitution failed:
dt.cpp:7:50: note:   mismatched types ‘const std::__cxx11::basic_string<CharT,
Traits, Alloc>’ and ‘const char [18]’
    7 |  str >> date::parse("%Y-%m-%d %H:%M:%S", loc_time);

FYI, I will also notify Howard Hinnant of this issue because he might have a
clue as to the cause of the problem.

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

* [Bug libstdc++/94869] [10 Regression] Template argument deduction/substitution failure with Howard Hinnant's calendar library
  2020-04-30  8:18 [Bug c++/94869] New: Template argument deduction/substitution failure with Howard Hinnant's calendar library lcarreon at bigpond dot net.au
@ 2020-04-30  9:11 ` rguenth at gcc dot gnu.org
  2020-04-30 13:48 ` redi at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-04-30  9:11 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid
   Last reconfirmed|                            |2020-04-30
   Target Milestone|---                         |10.0
            Summary|Template argument           |[10 Regression] Template
                   |deduction/substitution      |argument
                   |failure with Howard         |deduction/substitution
                   |Hinnant's calendar library  |failure with Howard
                   |                            |Hinnant's calendar library
          Component|c++                         |libstdc++
             Status|UNCONFIRMED                 |WAITING
     Ever confirmed|0                           |1

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Can you provide a complete testcase?  I'm sure date.h does not include
any STL bits.  That is, please provide preprocessed source.

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

* [Bug libstdc++/94869] [10 Regression] Template argument deduction/substitution failure with Howard Hinnant's calendar library
  2020-04-30  8:18 [Bug c++/94869] New: Template argument deduction/substitution failure with Howard Hinnant's calendar library lcarreon at bigpond dot net.au
  2020-04-30  9:11 ` [Bug libstdc++/94869] [10 Regression] " rguenth at gcc dot gnu.org
@ 2020-04-30 13:48 ` redi at gcc dot gnu.org
  2020-04-30 16:03 ` redi at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2020-04-30 13:48 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
It includes tons of std::lib headers:

#include <cassert>
#include <algorithm>
#include <cctype>
#include <chrono>
#include <climits>
#if !(__cplusplus >= 201402)
#  include <cmath>
#endif
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <ctime>
#include <ios>
#include <istream>
#include <iterator>
#include <limits>
#include <locale>
#include <memory>
#include <ostream>
#include <ratio>
#include <sstream>
#include <stdexcept>
#include <string>
#if HAS_STRING_VIEW
# include <string_view>
#endif
#include <utility>
#include <type_traits>

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

* [Bug libstdc++/94869] [10 Regression] Template argument deduction/substitution failure with Howard Hinnant's calendar library
  2020-04-30  8:18 [Bug c++/94869] New: Template argument deduction/substitution failure with Howard Hinnant's calendar library lcarreon at bigpond dot net.au
  2020-04-30  9:11 ` [Bug libstdc++/94869] [10 Regression] " rguenth at gcc dot gnu.org
  2020-04-30 13:48 ` redi at gcc dot gnu.org
@ 2020-04-30 16:03 ` redi at gcc dot gnu.org
  2020-04-30 16:05 ` redi at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2020-04-30 16:03 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[10/11 Regression] Template |[10 Regression] Template
                   |argument                    |argument
                   |deduction/substitution      |deduction/substitution
                   |failure with Howard         |failure with Howard
                   |Hinnant's calendar library  |Hinnant's calendar library

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Leo Carreon from comment #0)
> The following bit of code used to compile ok with g++ 9.2.1.

Are you sure? With 9.2 or 9.3 I get:


date.cc: In function 'int main()':
date.cc:6:18: error: 'local_time' is not a member of 'std::chrono'; did you
mean 'date::local_time'?
    6 |     std::chrono::local_time<std::chrono::milliseconds> loc_time;
      |                  ^~~~~~~~~~
In file included from date.cc:1:
/home/jwakely/src/date/include/date/date.h:201:11: note: 'date::local_time'
declared here
  201 |     using local_time = std::chrono::time_point<local_t, Duration>;
      |           ^~~~~~~~~~
date.cc:6:54: error: expected primary-expression before '>' token
    6 |     std::chrono::local_time<std::chrono::milliseconds> loc_time;
      |                                                      ^
date.cc:6:56: error: 'loc_time' was not declared in this scope; did you mean
'localtime'?
    6 |     std::chrono::local_time<std::chrono::milliseconds> loc_time;
      |                                                        ^~~~~~~~
      |                                                        localtime

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

* [Bug libstdc++/94869] [10 Regression] Template argument deduction/substitution failure with Howard Hinnant's calendar library
  2020-04-30  8:18 [Bug c++/94869] New: Template argument deduction/substitution failure with Howard Hinnant's calendar library lcarreon at bigpond dot net.au
                   ` (2 preceding siblings ...)
  2020-04-30 16:03 ` redi at gcc dot gnu.org
@ 2020-04-30 16:05 ` redi at gcc dot gnu.org
  2020-04-30 16:14 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2020-04-30 16:05 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
std::local_time is new for GCC 10, so I would not expect the code to compile
with odler versions. I would also not expect std::chrono::local_time to work
with date::parse because date::parse probably only knows about date::local_t
and not std::chrono::local_t.

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

* [Bug libstdc++/94869] [10 Regression] Template argument deduction/substitution failure with Howard Hinnant's calendar library
  2020-04-30  8:18 [Bug c++/94869] New: Template argument deduction/substitution failure with Howard Hinnant's calendar library lcarreon at bigpond dot net.au
                   ` (3 preceding siblings ...)
  2020-04-30 16:05 ` redi at gcc dot gnu.org
@ 2020-04-30 16:14 ` redi at gcc dot gnu.org
  2020-04-30 21:41 ` lcarreon at bigpond dot net.au
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2020-04-30 16:14 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
If I change your code to use date::local_time (as suggested by GCC 9) then it
compiles as expected with any recent version of GCC.

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

* [Bug libstdc++/94869] [10 Regression] Template argument deduction/substitution failure with Howard Hinnant's calendar library
  2020-04-30  8:18 [Bug c++/94869] New: Template argument deduction/substitution failure with Howard Hinnant's calendar library lcarreon at bigpond dot net.au
                   ` (4 preceding siblings ...)
  2020-04-30 16:14 ` redi at gcc dot gnu.org
@ 2020-04-30 21:41 ` lcarreon at bigpond dot net.au
  2020-04-30 22:01 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: lcarreon at bigpond dot net.au @ 2020-04-30 21:41 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Leo Carreon <lcarreon at bigpond dot net.au> ---
Thanks for your comments.  I have realized what the issue is.  It is to do with
local_time and local_days being defined in namespace date and std::chrono.

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

* [Bug libstdc++/94869] [10 Regression] Template argument deduction/substitution failure with Howard Hinnant's calendar library
  2020-04-30  8:18 [Bug c++/94869] New: Template argument deduction/substitution failure with Howard Hinnant's calendar library lcarreon at bigpond dot net.au
                   ` (5 preceding siblings ...)
  2020-04-30 21:41 ` lcarreon at bigpond dot net.au
@ 2020-04-30 22:01 ` redi at gcc dot gnu.org
  2020-04-30 22:28 ` lcarreon at bigpond dot net.au
  2020-05-01  7:35 ` redi at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2020-04-30 22:01 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |RESOLVED
         Resolution|---                         |INVALID

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
That doesn't explain why you claim the code worked with GCC 9.

I'm going to assume this was user error, as I don't see a bug in libstdc++.

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

* [Bug libstdc++/94869] [10 Regression] Template argument deduction/substitution failure with Howard Hinnant's calendar library
  2020-04-30  8:18 [Bug c++/94869] New: Template argument deduction/substitution failure with Howard Hinnant's calendar library lcarreon at bigpond dot net.au
                   ` (6 preceding siblings ...)
  2020-04-30 22:01 ` redi at gcc dot gnu.org
@ 2020-04-30 22:28 ` lcarreon at bigpond dot net.au
  2020-05-01  7:35 ` redi at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: lcarreon at bigpond dot net.au @ 2020-04-30 22:28 UTC (permalink / raw)
  To: gcc-bugs

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

Leo Carreon <lcarreon at bigpond dot net.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |CLOSED

--- Comment #8 from Leo Carreon <lcarreon at bigpond dot net.au> ---
My code was checking the value of __cpp_lib_chrono for the value when calendars
and timezones are introduced.  When its below this value, it maps namespace
date to namespace std::chrono.  Now I realize that this is not advisable
because you are starting to partially implement the feature which caused the
conflict.  The lesson learned from this is I have to change my strategy of
using sample imlementations of a feature.  I'm closing this bug report.

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

* [Bug libstdc++/94869] [10 Regression] Template argument deduction/substitution failure with Howard Hinnant's calendar library
  2020-04-30  8:18 [Bug c++/94869] New: Template argument deduction/substitution failure with Howard Hinnant's calendar library lcarreon at bigpond dot net.au
                   ` (7 preceding siblings ...)
  2020-04-30 22:28 ` lcarreon at bigpond dot net.au
@ 2020-05-01  7:35 ` redi at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2020-05-01  7:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from Jonathan Wakely <redi at gcc dot gnu.org> ---
OK thanks for confirming that.

N.B. this is why you're supposed to provide preprocessed source. The code you
showed to demonstrate the bug did *not* demonstrate it, because you were
actually using something different (a modified version of <date.h>, or some
extra code not shown in your example).

Opening namespace std to add your own declarations to it (such as
using-declarations of ::date::local_time) is forbidden, resulting in undefined
behaviour. The result you got here is a good example of why. Instead of trying
to add things to namespace std, you should do something like:

#include <chrono>
#if __cpp_lib_chrono >= 201803L
namespace time = std::chrono;
#else
#include <date/date.h>
namespace time = date;
#endif
// use time::duration, time::local_time etc.

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

end of thread, other threads:[~2020-05-01  7:35 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-30  8:18 [Bug c++/94869] New: Template argument deduction/substitution failure with Howard Hinnant's calendar library lcarreon at bigpond dot net.au
2020-04-30  9:11 ` [Bug libstdc++/94869] [10 Regression] " rguenth at gcc dot gnu.org
2020-04-30 13:48 ` redi at gcc dot gnu.org
2020-04-30 16:03 ` redi at gcc dot gnu.org
2020-04-30 16:05 ` redi at gcc dot gnu.org
2020-04-30 16:14 ` redi at gcc dot gnu.org
2020-04-30 21:41 ` lcarreon at bigpond dot net.au
2020-04-30 22:01 ` redi at gcc dot gnu.org
2020-04-30 22:28 ` lcarreon at bigpond dot net.au
2020-05-01  7:35 ` 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).