LoginSignup
0
0

More than 1 year has passed since last update.

29.9 Class template hh_mm_ss [time.hms] C++N4910:2022 (677) p1422.cpp

Posted at

はじめに(Introduction)

N4910 Working Draft, Standard for Programming Language C++

n4910は、ISO/IEC JTC1 SC22 WG21の作業原案(Working Draft)です。
公式のISO/IEC 14882原本ではありません。
ISO/IEC JTC1 SC22 WG21では、可能な限り作業文書を公開し、幅広い意見を求めています。
一連の記事はコード断片をコンパイルできる形にする方法を検討してコンパイル、リンク、実行して、規格案の原文と処理系(g++, Clang++)との違いを確認し、技術内容を検討し、ISO/IEC JTC1 SC22 WG21にフィードバックするために用います。
また、CERT C++, MISRA C++等のコーディング標準のコード断片をコンパイルする際の参考にさせていただこうと考えています。CERT C++, MISRA C++が標準化の動きとの時間的なずれがあれば確認できれば幸いです。また、boostライブラリとの関連、Linux OS, TOPPERSカーネル、g++(GCC), clang++(LLVM)との関係も調査中です。
何か、抜け漏れ、耳より情報がありましたらおしらせくださると幸いです。

<この項は書きかけです。順次追記します。>

背景(back ground)

C/C++でコンパイルエラーが出ると、途方にくれることがしばしばあります。
何回かに1回は、該当するエラーが検索できます。
ただ、条件が違っていて、そこでの修正方法では目的を達成しないこともしばしばです。いろいろな条件のコンパイルエラーとその対応方法について、広く記録することによって、いつか同じエラーに遭遇した時にやくに立つことを目指しています。

この半年の間で、三度、自分のネットでの記録に助けられたことがあります。
また過去に解決できなかった記録を10種類以上、最近になって解決できたことがあります。それは、主に次の3つの情報に基づいています。

cpprefjp - C++日本語リファレンス

コンパイラの実装状況

また
https://researchmap.jp/joub9b3my-1797580/#_1797580
に記載したサイトのお世話になっています。

作業方針(sequence)

Clang++では-std=c++03, C++2bの2種類
g++では-std=c++03, c++2bの2種類
でコンパイルし、

1)コンパイルエラーを収集する。
2)コンパイルエラーをなくす方法を検討する。
コンパイルエラーになる例を示すだけが目的のコードは、コンパイルエラーをなくすのではなく、コンパイルエラーの種類を収集するだけにする。
文法を示すのが目的のコード場合に、コンパイルエラーをなくすのに手間がかかる場合は、順次作業します。
3)リンクエラーをなくす方法を検討する。
文法を示すのが目的のコード場合に、リンクエラーをなくすのに手間がかかる場合は、順次作業します。
4)意味のある出力を作る。
コンパイル、リンクが通っても、意味のある出力を示そうとすると、コンパイル・リンクエラーが出て収拾できそうにない場合がある。順次作業します。

1)だけのものから4)まで進んだものと色々ある状態です。一歩でも前に進むご助言をお待ちしています。「検討事項」の欄に現状を記録するようにしています。

C++N4910:2022 Standard Working Draft on ISO/IEC 14882(0) sample code compile list

C++N4741, 2018 Standard Working Draft on ISO/IEC 14882 sample code compile list

C++N4606, 2016符号断片編纂一覧(example code compile list)

C++N4606, 2016 Working Draft 2016, ISO/IEC 14882, C++ standard(1) Example code compile list
https://qiita.com/kaizen_nagoya/items/df5d62c35bd6ed1c3d43/

C++N3242, 2011 sample code compile list on clang++ and g++

編纂器(Compiler)

clang++ --version

Debian clang version 14.0.5-++20220610033153+c12386ae247c-1~exp1~20220610153237.151
Target: x86_64-pc-linux-gnu, Thread model: posix, InstalledDir: /usr/bin

g++- --version

g++ (GCC) 12.1.0 Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

29.9 Class template hh_mm_ss [time.hms] C++N4910:2022 (677) p1422.cpp

算譜(source code)

p1422.cpp
// C++N4910 Committee Draft, Standard for Programming Language C++
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/n4910.pdf
const char * n4910 = " 29.9 Class template hh_mm_ss [time.hms]  C++N4910:2022 (677) p1422.cpp";
// Debian clang version 14.0.5-++20220610033153+c12386ae247c-
// g++ (GCC) 12.1.0 Copyright (C) 2022 Free Software Foundation, Inc.
// Edited by Dr. OGAWA Kiyoshi. Compile procedure and results record.
// C++N4910:2022 Standard Working Draft on ISO/IEC 14882(0) sample code compile list
// https://qiita.com/kaizen_nagoya/items/fc957ddddd402004bb91

#include "N4910.h"

using namespace std;

// 29.9.1 Overview [time.hms.overview]
namespace std::chrono {
template<class Duration> class hh_mm_ss {
public:
    static constexpr unsigned fractional_width = see below;
    using precision = see below;
    constexpr hh_mm_ss() noexcept : hh_mm_ss {
        Duration::zero()
    } {}
    constexpr explicit hh_mm_ss(Duration d);
    constexpr bool is_negative() const noexcept;
    constexpr chrono::hours hours() const noexcept;
    constexpr chrono::minutes minutes() const noexcept;
    constexpr chrono::seconds seconds() const noexcept;
    constexpr precision subseconds() const noexcept;
    constexpr explicit operator precision() const noexcept;
    constexpr precision to_duration() const noexcept;
private:
    bool            is_neg;
    chrono::hours   h;
    chrono::minutes m;
    chrono::seconds s;
    precision       ss;
};
}
// exposition only // exposition only // exposition only // exposition only // exposition only
//  The hh_mm_ss class template splits a duration into a multi-field time structure hours:minutes:seconds and possibly subseconds, where subseconds will be a duration unit based on a non-positive power of 10. The Duration template parameter dictates the precision to which the time is split. A hh_mm_ss models negative durations with a distinct is_negative getter that returns true when the input duration is negative. The individual duration fields always return non-negative durations even when is_negative() indicates the structure is representing a negative duration.
//  If Duration is not a specialization of duration, the program is ill-formed.
// 29.9.2 Members [time.hms.members]
static constexpr unsigned fractional_width = see_below;
// fractional_width is the number of fractional decimal digits represented by precision. fractional_- width has the value of the smallest possible integer in the range [0, 18] such that precision will exactly represent all values of Duration. If no such value of fractional_width exists, then fractional_width is 6.
// [Example 1: See Table 96 for some durations, the resulting fractional_width, and the formatted fractional second output of Duration{1}.
// Table 96: Examples for fractional_width [tab:time.hms.width]
//Duration fractional_width Formatted fractional second output
hours, minutes, and seconds 0
milliseconds 3 0.001
microseconds 6 0.000001
using precision = see below;
precision is
duration<common_type_t<Duration::rep, seconds::rep>, ratio<1, 10fractional_width>> constexpr explicit hh_mm_ss(Duration d);
// Table 96: Examples for fractional_width (continued)
//    Duration fractional_width Formatted fractional second output
nanoseconds 9 0.000000001
duration<int, ratio<1, 2>> 1 0.5
                        duration<int, ratio<1, 3>> 6 0.333333
                        duration<int, ratio<1, 4>> 2 0.25
                        duration<int, ratio<1, 5>> 1 0.2
                        duration<int, ratio<1, 6>> 6 0.166666
                        duration<int, ratio<1, 7>> 6 0.142857
                        duration<int, ratio<1, 8>> 3 0.125
                        duration<int, ratio<1, 9>> 6 0.111111
                        duration<int, ratio<1, 10>> 1 0.1
                        duration<int, ratio<756, 625>> 4 0.2096
//  Effects: Constructs an object of type hh_mm_ss which represents the Duration d with precision precision.
// — Initializes is_neg with d < Duration::zero().
// — Initializes h with duration_cast<chrono::hours>(abs(d)).
// — Initializes m with duration_cast<chrono::minutes>(abs(d) - hours()).
// — Initializes s with duration_cast<chrono::seconds>(abs(d) - hours() - minutes()).
// — If treat_as_floating_point_v<precision::rep> is true, initializes ss with abs(d) - hours() - minutes() - seconds(). Otherwise, initializes ss with duration_cast<precision>(abs(d) - hours() - minutes() - seconds()).
// [Note 1: When precision::rep is integral and precision::period is ratio<1>, subseconds() always returns a value equal to 0s.
// Postconditions: If treat_as_floating_point_v<precision::rep> is true, to_duration() returns d, otherwise to_duration() returns duration_cast<precision>(d).
                        constexpr bool is_negative() const noexcept;
// Returns: is_neg.
constexpr chrono::hours hours() const noexcept;
// Returns: h.
constexpr chrono::minutes minutes() const noexcept;
// Returns: m.
constexpr chrono::seconds seconds() const noexcept;
// Returns: s.
constexpr precision subseconds() const noexcept;
// Returns: ss.
constexpr precision to_duration() const noexcept;
// Returns: If is_neg, returns -(h + m + s + ss), otherwise returns h + m + s + ss.
constexpr explicit operator precision() const noexcept;
// Returns: to_duration().
// 29.9.3 Non-members [time.hms.nonmembers]
template<class charT, class traits, class Duration>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os, const hh_mm_ss<Duration>& hms);
// Effects: Equivalent to:
return os << format(os.getloc(), STATICALLY-WIDEN<charT>("{:L%T}"), hms);
// [Example 1:
for (auto ms : {
            -4083007ms, 4083007ms, 65745123ms
            }) {
    hh_mm_ss hms{ms};
    cout << hms << '\n';
}
cout << hh_mm_ss{65745s} << '\n';
// Produces the output (assuming the "C" locale):
-01:08:03.007
    01:08:03.007
    18:15:45.123
    18:15:45
    int main() {
    cout  <<  n4910 << endl;
    return EXIT_SUCCESS;
}:

編纂・実行結果(compile and go)

bash
$ clang++ p1422.cpp -std=03 -o p1422l -I. -Wall
In file included from p1422.cpp:10:
In file included from ./N4910.h:11:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/atomic:38:
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/c++0x_warning.h:32:2: error: This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
#error This file requires compiler and library support \
 ^
p1422.cpp:15:16: warning: nested namespace definition is a C++17 extension; define each namespace separately [-Wc++17-extensions]
  namespace std::chrono {
               ^~~~~~~~
                { namespace chrono
p1422.cpp:18:8: error: unknown type name 'constexpr'
static constexpr unsigned fractional_width = see below; using precision = see below;
       ^
p1422.cpp:18:46: error: use of undeclared identifier 'see'
static constexpr unsigned fractional_width = see below; using precision = see below;
                                             ^
p1422.cpp:18:49: error: expected ';' at end of declaration list
static constexpr unsigned fractional_width = see below; using precision = see below;
                                                ^
                                                ;
p1422.cpp:18:75: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
static constexpr unsigned fractional_width = see below; using precision = see below;
                                                                          ^
p1422.cpp:18:75: error: unknown type name 'see'
p1422.cpp:18:79: error: type-id cannot have a name
static constexpr unsigned fractional_width = see below; using precision = see below;
                                                                              ^~~~~
p1422.cpp:19:7: error: unknown type name 'constexpr'
      constexpr hh_mm_ss() noexcept : hh_mm_ss{Duration::zero()} {}
      ^
p1422.cpp:19:17: error: constructor cannot have a return type
      constexpr hh_mm_ss() noexcept : hh_mm_ss{Duration::zero()} {}
                ^~~~~~~~
p1422.cpp:19:27: error: expected ';' at end of declaration list
      constexpr hh_mm_ss() noexcept : hh_mm_ss{Duration::zero()} {}
                          ^
                          ;
p1422.cpp:21:7: error: unknown type name 'constexpr'
      constexpr bool is_negative() const noexcept;
      ^
p1422.cpp:21:41: error: expected ';' at end of declaration list
      constexpr bool is_negative() const noexcept;
                                        ^
                                        ;
p1422.cpp:22:7: error: unknown type name 'constexpr'
      constexpr chrono::hours hours() const noexcept;
      ^
p1422.cpp:22:25: error: non-friend class member 'hours' cannot have a qualified name
      constexpr chrono::hours hours() const noexcept;
                ~~~~~~~~^
p1422.cpp:22:30: error: expected ';' at end of declaration list
      constexpr chrono::hours hours() const noexcept;
                             ^
                             ;
p1422.cpp:23:7: error: unknown type name 'constexpr'
      constexpr chrono::minutes minutes() const noexcept;
      ^
p1422.cpp:23:25: error: non-friend class member 'minutes' cannot have a qualified name
      constexpr chrono::minutes minutes() const noexcept;
                ~~~~~~~~^
p1422.cpp:23:32: error: expected ';' at end of declaration list
      constexpr chrono::minutes minutes() const noexcept;
                               ^
                               ;
p1422.cpp:24:7: error: unknown type name 'constexpr'
      constexpr chrono::seconds seconds() const noexcept;
      ^
p1422.cpp:24:25: error: non-friend class member 'seconds' cannot have a qualified name
      constexpr chrono::seconds seconds() const noexcept;
                ~~~~~~~~^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
2 warnings and 20 errors generated.
$ clang++ p1422.cpp -std=2b -o p1422l -I. -Wall
p1422.cpp:18:46: error: use of undeclared identifier 'see'
static constexpr unsigned fractional_width = see below; using precision = see below;
                                             ^
p1422.cpp:18:49: error: expected ';' at end of declaration list
static constexpr unsigned fractional_width = see below; using precision = see below;
                                                ^
                                                ;
p1422.cpp:18:75: error: unknown type name 'see'
static constexpr unsigned fractional_width = see below; using precision = see below;
                                                                          ^
p1422.cpp:18:79: error: type-id cannot have a name
static constexpr unsigned fractional_width = see below; using precision = see below;
                                                                              ^~~~~
p1422.cpp:22:25: error: no type named 'hours' in namespace 'std::chrono'
      constexpr chrono::hours hours() const noexcept;
                ~~~~~~~~^
p1422.cpp:23:25: error: no type named 'minutes' in namespace 'std::chrono'
      constexpr chrono::minutes minutes() const noexcept;
                ~~~~~~~~^
p1422.cpp:24:25: error: no type named 'seconds' in namespace 'std::chrono'
      constexpr chrono::seconds seconds() const noexcept;
                ~~~~~~~~^
p1422.cpp:25:17: error: unknown type name 'precision'
      constexpr precision subseconds() const noexcept;
                ^
p1422.cpp:26:35: error: unknown type name 'precision'
      constexpr explicit operator precision() const noexcept;
                                  ^
p1422.cpp:27:17: error: unknown type name 'precision'
      constexpr precision to_duration() const noexcept;
                ^
p1422.cpp:30:13: error: no type named 'hours' in namespace 'std::chrono'
    chrono::hours   h;
    ~~~~~~~~^
p1422.cpp:31:13: error: no type named 'minutes' in namespace 'std::chrono'
    chrono::minutes m;
    ~~~~~~~~^
p1422.cpp:32:13: error: no type named 'seconds' in namespace 'std::chrono'
    chrono::seconds s;
    ~~~~~~~~^
p1422.cpp:33:5: error: unknown type name 'precision'
    precision       ss;
    ^
p1422.cpp:39:46: error: use of undeclared identifier 'see_below'
static constexpr unsigned fractional_width = see_below;
                                             ^
p1422.cpp:44:1: error: C++ requires a type specifier for all declarations
hours, minutes, and seconds 0
^
p1422.cpp:44:8: error: no template named 'minutes'; did you mean 'minus'?
hours, minutes, and seconds 0
       ^~~~~~~
       minus
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_function.h:177:12: note: 'minus' declared here
    struct minus : public binary_function<_Tp, _Tp, _Tp>
           ^
p1422.cpp:44:28: error: expected ';' after top level declarator
hours, minutes, and seconds 0
                           ^
                           ;
p1422.cpp:47:30: error: unknown type name 'precision'
using precision = see below; precision is
                             ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.

$ g++ p1422.cpp -std=03 -o p1422g -I. -Wall
In file included from /usr/local/include/c++/12.1.0/atomic:38,
                 from N4910.h:11,
                 from p1422.cpp:10:
/usr/local/include/c++/12.1.0/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
   32 | #error This file requires compiler and library support \
      |  ^~~~~
p1422.cpp:18:8: warning: identifier 'constexpr' is a keyword in C++11 [-Wc++11-compat]
   18 | static constexpr unsigned fractional_width = see below; using precision = see below;
      |        ^~~~~~~~~
p1422.cpp:19:28: warning: identifier 'noexcept' is a keyword in C++11 [-Wc++11-compat]
   19 |       constexpr hh_mm_ss() noexcept : hh_mm_ss{Duration::zero()} {}
      |                            ^~~~~~~~
p1422.cpp:48:63: error: invalid suffix "fractional_width" on integer constant
   48 | duration<common_type_t<Duration::rep, seconds::rep>, ratio<1, 10fractional_width>> constexpr explicit hh_mm_ss(Duration d);
      |                                                               ^~~~~~~~~~~~~~~~~~
p1422.cpp:91:20: error: invalid suffix "ms" on integer constant
   91 |   for (auto ms : {-4083007ms, 4083007ms, 65745123ms}) {
      |                    ^~~~~~~~~
p1422.cpp:91:31: error: invalid suffix "ms" on integer constant
   91 |   for (auto ms : {-4083007ms, 4083007ms, 65745123ms}) {
      |                               ^~~~~~~~~
p1422.cpp:91:42: error: invalid suffix "ms" on integer constant
   91 |   for (auto ms : {-4083007ms, 4083007ms, 65745123ms}) {
      |                                          ^~~~~~~~~~
p1422.cpp:95:20: error: invalid suffix "s" on integer constant
   95 |   cout << hh_mm_ss{65745s} << '\n';
      |                    ^~~~~~
p1422.cpp:97:7: error: invalid digit "8" in octal constant
   97 |   -01:08:03.007
      |       ^~
p1422.cpp:98:6: error: invalid digit "8" in octal constant
   98 |   01:08:03.007
      |      ^~
p1422.cpp:18:8: error: 'constexpr' does not name a type
   18 | static constexpr unsigned fractional_width = see below; using precision = see below;
      |        ^~~~~~~~~
p1422.cpp:18:8: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p1422.cpp:18:63: error: expected nested-name-specifier before 'precision'
   18 | static constexpr unsigned fractional_width = see below; using precision = see below;
      |                                                               ^~~~~~~~~
p1422.cpp:19:7: error: 'constexpr' does not name a type
   19 |       constexpr hh_mm_ss() noexcept : hh_mm_ss{Duration::zero()} {}
      |       ^~~~~~~~~
p1422.cpp:19:7: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p1422.cpp:19:66: error: expected unqualified-id before '{' token
   19 |       constexpr hh_mm_ss() noexcept : hh_mm_ss{Duration::zero()} {}
      |                                                                  ^
p1422.cpp:20:7: error: 'constexpr' does not name a type
   20 |       constexpr explicit hh_mm_ss(Duration d);
      |       ^~~~~~~~~
p1422.cpp:20:7: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p1422.cpp:21:7: error: 'constexpr' does not name a type
   21 |       constexpr bool is_negative() const noexcept;
      |       ^~~~~~~~~
p1422.cpp:21:7: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p1422.cpp:22:7: error: 'constexpr' does not name a type
   22 |       constexpr chrono::hours hours() const noexcept;
      |       ^~~~~~~~~
p1422.cpp:22:7: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p1422.cpp:23:7: error: 'constexpr' does not name a type
   23 |       constexpr chrono::minutes minutes() const noexcept;
      |       ^~~~~~~~~
p1422.cpp:23:7: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p1422.cpp:24:7: error: 'constexpr' does not name a type
   24 |       constexpr chrono::seconds seconds() const noexcept;
      |       ^~~~~~~~~
p1422.cpp:24:7: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p1422.cpp:25:7: error: 'constexpr' does not name a type
   25 |       constexpr precision subseconds() const noexcept;
      |       ^~~~~~~~~
p1422.cpp:25:7: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p1422.cpp:26:7: error: 'constexpr' does not name a type
   26 |       constexpr explicit operator precision() const noexcept;
      |       ^~~~~~~~~
p1422.cpp:26:7: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p1422.cpp:27:7: error: 'constexpr' does not name a type
   27 |       constexpr precision to_duration() const noexcept;
      |       ^~~~~~~~~
p1422.cpp:27:7: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p1422.cpp:30:13: error: 'hours' in namespace 'std::chrono' does not name a type
   30 |     chrono::hours   h;
      |             ^~~~~
p1422.cpp:31:13: error: 'minutes' in namespace 'std::chrono' does not name a type
   31 |     chrono::minutes m;
      |             ^~~~~~~
p1422.cpp:32:13: error: 'seconds' in namespace 'std::chrono' does not name a type
   32 |     chrono::seconds s;
      |             ^~~~~~~
p1422.cpp:33:5: error: 'precision' does not name a type
   33 |     precision       ss;
      |     ^~~~~~~~~
p1422.cpp:39:8: error: 'constexpr' does not name a type
   39 | static constexpr unsigned fractional_width = see_below;
      |        ^~~~~~~~~
p1422.cpp:39:8: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p1422.cpp:44:1: error: 'hours' does not name a type
   44 | hours, minutes, and seconds 0
      | ^~~~~
p1422.cpp:47:30: error: 'precision' does not name a type
   47 | using precision = see below; precision is
      |                              ^~~~~~~~~
p1422.cpp:51:5: error: 'nanoseconds' does not name a type
   51 |     nanoseconds 9 0.000000001
      |     ^~~~~~~~~~~
p1422.cpp:72:1: error: 'constexpr' does not name a type
   72 | constexpr chrono::hours hours() const noexcept;
      | ^~~~~~~~~
p1422.cpp:72:1: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p1422.cpp:74:1: error: 'constexpr' does not name a type
   74 | constexpr chrono::minutes minutes() const noexcept;
      | ^~~~~~~~~
p1422.cpp:74:1: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p1422.cpp:76:1: error: 'constexpr' does not name a type
   76 | constexpr chrono::seconds seconds() const noexcept;
      | ^~~~~~~~~
p1422.cpp:76:1: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p1422.cpp:78:1: error: 'constexpr' does not name a type
   78 | constexpr precision subseconds() const noexcept;
      | ^~~~~~~~~
p1422.cpp:78:1: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p1422.cpp:80:1: error: 'constexpr' does not name a type
   80 | constexpr precision to_duration() const noexcept;
      | ^~~~~~~~~
p1422.cpp:80:1: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p1422.cpp:82:1: error: 'constexpr' does not name a type
   82 | constexpr explicit operator precision() const noexcept;
      | ^~~~~~~~~
p1422.cpp:82:1: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p1422.cpp:87:55: error: 'hh_mm_ss' does not name a type
   87 |    operator<<(basic_ostream<charT, traits>& os, const hh_mm_ss<Duration>& hms);
      |                                                       ^~~~~~~~
p1422.cpp:87:63: error: expected ',' or '...' before '<' token
   87 |    operator<<(basic_ostream<charT, traits>& os, const hh_mm_ss<Duration>& hms);
      |                                                               ^
p1422.cpp:89:1: error: expected unqualified-id before 'return'
   89 | return os << format(os.getloc(), STATICALLY-WIDEN<charT>("{:L%T}"), hms);
      | ^~~~~~
p1422.cpp:91:3: error: expected unqualified-id before 'for'
   91 |   for (auto ms : {-4083007ms, 4083007ms, 65745123ms}) {
      |   ^~~
p1422.cpp:91:53: error: expected unqualified-id before ')' token
   91 |   for (auto ms : {-4083007ms, 4083007ms, 65745123ms}) {
      |                                                     ^
p1422.cpp:95:3: error: 'cout' does not name a type
   95 |   cout << hh_mm_ss{65745s} << '\n';
      |   ^~~~
p1422.cpp:95:28: error: expected unqualified-id before '<<' token
   95 |   cout << hh_mm_ss{65745s} << '\n';
      |                            ^~
p1422.cpp:97:3: error: expected unqualified-id before '-' token
   97 |   -01:08:03.007
      |   ^
p1422.cpp:104:2: error: expected unqualified-id before ':' token
  104 | }:
      |  ^

$ g++ p1422.cpp -std=2b -o p1422g -I. -Wall
p1422.cpp:97:7: error: invalid digit "8" in octal constant
   97 |   -01:08:03.007
      |       ^~
p1422.cpp:98:6: error: invalid digit "8" in octal constant
   98 |   01:08:03.007
      |      ^~
p1422.cpp:18:46: error: 'see' was not declared in this scope
   18 | static constexpr unsigned fractional_width = see below; using precision = see below;
      |                                              ^~~
p1422.cpp:18:46: error: expected ';' at end of member declaration
   18 | static constexpr unsigned fractional_width = see below; using precision = see below;
      |                                              ^~~
      |                                                 ;
p1422.cpp:18:50: error: 'below' does not name a type
   18 | static constexpr unsigned fractional_width = see below; using precision = see below;
      |                                                  ^~~~~
p1422.cpp:18:75: error: 'see' does not name a type
   18 | static constexpr unsigned fractional_width = see below; using precision = see below;
      |                                                                           ^~~
p1422.cpp:22:25: error: 'hours' in namespace 'std::chrono' does not name a type
   22 |       constexpr chrono::hours hours() const noexcept;
      |                         ^~~~~
p1422.cpp:23:25: error: 'minutes' in namespace 'std::chrono' does not name a type
   23 |       constexpr chrono::minutes minutes() const noexcept;
      |                         ^~~~~~~
p1422.cpp:24:25: error: 'seconds' in namespace 'std::chrono' does not name a type
   24 |       constexpr chrono::seconds seconds() const noexcept;
      |                         ^~~~~~~
p1422.cpp:25:17: error: 'precision' does not name a type
   25 |       constexpr precision subseconds() const noexcept;
      |                 ^~~~~~~~~
p1422.cpp:26:35: error: expected type-specifier before 'precision'
   26 |       constexpr explicit operator precision() const noexcept;
      |                                   ^~~~~~~~~
p1422.cpp:27:17: error: 'precision' does not name a type
   27 |       constexpr precision to_duration() const noexcept;
      |                 ^~~~~~~~~
p1422.cpp:30:13: error: 'hours' in namespace 'std::chrono' does not name a type
   30 |     chrono::hours   h;
      |             ^~~~~
p1422.cpp:31:13: error: 'minutes' in namespace 'std::chrono' does not name a type
   31 |     chrono::minutes m;
      |             ^~~~~~~
p1422.cpp:32:13: error: 'seconds' in namespace 'std::chrono' does not name a type
   32 |     chrono::seconds s;
      |             ^~~~~~~
p1422.cpp:33:5: error: 'precision' does not name a type
   33 |     precision       ss;
      |     ^~~~~~~~~
p1422.cpp:39:46: error: 'see_below' was not declared in this scope
   39 | static constexpr unsigned fractional_width = see_below;
      |                                              ^~~~~~~~~
p1422.cpp:44:1: error: 'hours' does not name a type
   44 | hours, minutes, and seconds 0
      | ^~~~~
p1422.cpp:47:30: error: 'precision' does not name a type
   47 | using precision = see below; precision is
      |                              ^~~~~~~~~
p1422.cpp:51:5: error: 'nanoseconds' does not name a type
   51 |     nanoseconds 9 0.000000001
      |     ^~~~~~~~~~~
p1422.cpp:72:19: error: 'hours' in namespace 'std::chrono' does not name a type
   72 | constexpr chrono::hours hours() const noexcept;
      |                   ^~~~~
p1422.cpp:74:19: error: 'minutes' in namespace 'std::chrono' does not name a type
   74 | constexpr chrono::minutes minutes() const noexcept;
      |                   ^~~~~~~
p1422.cpp:76:19: error: 'seconds' in namespace 'std::chrono' does not name a type
   76 | constexpr chrono::seconds seconds() const noexcept;
      |                   ^~~~~~~
p1422.cpp:78:11: error: 'precision' does not name a type
   78 | constexpr precision subseconds() const noexcept;
      |           ^~~~~~~~~
p1422.cpp:80:11: error: 'precision' does not name a type
   80 | constexpr precision to_duration() const noexcept;
      |           ^~~~~~~~~
p1422.cpp:82:29: error: expected type-specifier before 'precision'
   82 | constexpr explicit operator precision() const noexcept;
      |                             ^~~~~~~~~
p1422.cpp:87:55: error: 'hh_mm_ss' does not name a type
   87 |    operator<<(basic_ostream<charT, traits>& os, const hh_mm_ss<Duration>& hms);
      |                                                       ^~~~~~~~
p1422.cpp:87:63: error: expected ',' or '...' before '<' token
   87 |    operator<<(basic_ostream<charT, traits>& os, const hh_mm_ss<Duration>& hms);
      |                                                               ^
p1422.cpp:89:1: error: expected unqualified-id before 'return'
   89 | return os << format(os.getloc(), STATICALLY-WIDEN<charT>("{:L%T}"), hms);
      | ^~~~~~
p1422.cpp:91:3: error: expected unqualified-id before 'for'
   91 |   for (auto ms : {-4083007ms, 4083007ms, 65745123ms}) {
      |   ^~~
p1422.cpp:91:53: error: expected unqualified-id before ')' token
   91 |   for (auto ms : {-4083007ms, 4083007ms, 65745123ms}) {
      |                                                     ^
p1422.cpp:95:3: error: 'cout' does not name a type
   95 |   cout << hh_mm_ss{65745s} << '\n';
      |   ^~~~
p1422.cpp:95:28: error: expected unqualified-id before '<<' token
   95 |   cout << hh_mm_ss{65745s} << '\n';
      |                            ^~
p1422.cpp:97:3: error: expected unqualified-id before '-' token
   97 |   -01:08:03.007
      |   ^
p1422.cpp:104:2: error: expected unqualified-id before ':' token
  104 | }:
      |  ^

検討事項(agenda)

コンパイルエラーを取るか、コンパイルエラーの理由を解説する。

応用例1 AUTOSAR C++

AUTOSARでC++のコーディング標準を作っている。 
MISRA-C++コーディング標準の改訂をまたずに、C++14に対応したかったためかもしれない。 

Autosar Guidelines C++14 example code compile list

MISRA C++, AUTOSAR C++について

応用例2 MISRA C/C++

MISRA C まとめ #include

MISRA C++ 5-0-16

応用例3 CERT C/C++

SEI CERT C++ Coding Standard AA. Bibliography 確認中。

MISRA C/C++, AUTOSAR C++, CERT C/C++とC/C++工業標準をコンパイルする

応用例4 箱庭 

箱庭ではUnityをはじめC++を使っているらしい。 

ここでコンパイルしたコードと同じようなコードを使っているか、
ここで出たコンパイルエラーと同じようなエラーがでたかを
いろいろな版のコンパイラでコンパイルして確認していく。

仮想戦略会議「箱庭」

お盆には「箱庭」記事を書きましょう「もくもく会」の題材になる(1)

お盆には「箱庭」記事を書きましょう「もくもく会」の題材になる(2)

参考資料(reference)

エンジニア夏休み企画 個人開発

自己参考資料(self reference)

関連する自己参照以外は、こちらの先頭に移転。

C言語(C++)に対する誤解、曲解、無理解、爽快。

#include "N4910.h"

C++N4910資料の改善点

dockerにclang

docker gnu(gcc/g++) and llvm(clang/clang++)

コンパイル用shell script C版(clangとgcc)とC++版(clang++とg++)

C++N4910:2022 tag follower 300人超えました。ありがとうございます。

astyle 使ってみた

【個人開発】 効率的な背景 <エンジニア夏休み企画>

<この記事は個人の過去の経験に基づく個人の感想です。現在所属する組織、業務とは関係がありません。>

文書履歴(document history)

ver. 0.01 初稿  20220820

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0