0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

32.6 Class template regex_traits [re.traits] C++N4910:2022 (701) p1635.cpp

Last updated at Posted at 2022-09-20

はじめに(Introduction)

N4910 Working Draft, Standard for Programming Language C++

C++ n4910は、ISO/IEC JTC1 SC22 WG21の作業原案(Working Draft)です。
公式のISO/IEC 14882原本ではありません。
ISO/IEC JTC1 SC22 のWG21を含むいくつかのWGでは、可能な限り作業文書を公開し、幅広い意見を求めています。

ISO/IEC JTC1 SC7からISO/IEC JTC1 SC22リエゾンとして、2000年頃、C/C++の品質向上に貢献しようとした活動をしていたことがあります。その頃は、まだISO/IEC TS 17961の原案が出る前です。Cの精神が優勢で、セキュリティ対策は補助的な位置付けでした。ISO/IEC TS 17961の制定と、C/C++のライブラリ類の見直しと、C++の進化はどんどん進んでいきます。 

進化の具合が、どちらに行こうとしているかは、コンパイルて実行させてみないとわかりません。C/C++の規格案の電子ファイルは、そのままコンパイルできる形式であるとよいと主張してきました。MISRA-C/C++, CERTC/C++でも同様です。MISRA-C/C++は、Example Suiteという形で、コード断片をコンパイルできる形で提供するようになりました。

一連の記事はコード断片をコンパイルできる形にする方法を検討してコンパイル、リンク、実行して、規格案の原文と処理系(g++, Clang++)との違いを確認し、技術内容を検討し、ISO/IEC JTC1 SC22 WG21にフィードバックするために用います。
また、CERT C++, MISRA C++等のコーディング標準のコード断片をコンパイルする際の参考にさせていただこうと考えています。CERT C++, MISRA C++が標準化の動きとの時間的なずれがあれば確認できれば幸いです。また、boostライブラリとの関連、Linux OS, 箱庭プロジェクト、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

bash
$ docker run -v /Users/ogawakiyoshi/n4910:/Users/ogawakiyoshi/n4910 -it kaizenjapan/n4910 /bin/bash

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++

読書感想文

CコンパイラによるC言語規格の読書感想文として掲載しています。

コンパイル実験が、C++N4910に対する、G++とClang++による感想文だということご理解いただけると幸いです。

読書感想文は人間かAIだけが作るものとは限りません。
本(電子書籍を含む)を入力として、その内容に対する文字列を読書感想文として受け止めましょう。
元の文章をあり方、コンパイルできるように電子化しておくこと、コンパイラが解釈可能な断片の作り方など。

個人開発

Cコンパイラの試験を一人でもくもくとやっているのは個人開発の一つの姿です。

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

編纂器(Compiler)

clang++ --version

20220826 以前

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

20220827 以降

Debian clang version 14.0.6-++20220622053050+f28c006a5895-1~exp1~20220622173135.152
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.

32.6 Class template regex_traits [re.traits] C++N4910:2022 (700) p1635.cpp

算譜(source code)

p1635.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 = "32.6 Class template regex_traits [re.traits] C++N4910:2022 (701) p1635.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;

typedef int bitmask_type;
typedef char char_type;
typedef string string_type;
//32.6 C1lass template regex_traits [re.traits]
namespace std {
template<class charT>
struct regex_traits {
    using char_type = charT;
    using string_type = basic_string<char_type>;
    using locale_type = locale;
    using char_class_type = bitmask_type;
    regex_traits();
    static size_t length(const char_type* p);
    charT translate(charT c) const;
    charT translate_nocase(charT c) const;
    template<class ForwardIterator>
    string_type transform(ForwardIterator first, ForwardIterator last) const;
    template<class ForwardIterator>
    string_type transform_primary(
        ForwardIterator first, ForwardIterator last) const;
    template<class ForwardIterator>
    string_type lookup_collatename(
        ForwardIterator first, ForwardIterator last) const;
    template<class ForwardIterator>
    char_class_type lookup_classname(
        ForwardIterator first, ForwardIterator last, bool icase = false) const;
    bool isctype(charT c, char_class_type f) const;
    int value(charT ch, int radix) const;
    locale_type imbue(locale_type l);
    locale_type getloc() const;
};
}
//  The specializations regex_traits<char> and regex_traits<wchar_t> meet the requirements for a regular expression traits class (32.2).
using char_class_type = bitmask_type;
// The type char_class_type is used to represent a character classification and is capable of holding an implementation specific set returned by lookup_classname.
static size_t length(const char_type* p);
// Returns: char_traits<charT>::length(p).
charT translate(charT c) const;
// Returns: c.
charT translate_nocase(charT c) const;
// Returns: use_facet<ctype<charT>>(getloc()).tolower(c).
template<class ForwardIterator>
string_type transform(ForwardIterator first, ForwardIterator last) const;
// Effects: As if by:
string_type str(first, last);
return use_facet<collate<charT>>(
           getloc()).transform(str.data(), str.data() + str.length());
template<class ForwardIterator>
string_type transform_primary(ForwardIterator first, ForwardIterator last) const;
// Effects: If typeid(use_facet<collate<charT>>) == typeid(collate_byname<charT>) and the form of the sort key returned by collate_byname<charT>::transform(first, last) is known and can be converted into a primary sort key then returns that key, otherwise returns an empty string.
template<class ForwardIterator>
string_type lookup_collatename(ForwardIterator first, ForwardIterator last) const;
// Returns: A sequence of one or more characters that represents the collating element consisting of the character sequence designated by the iterator range [first, last). Returns an empty string if the character sequence is not a valid collating element.
template<class ForwardIterator>
char_class_type lookup_classname( ForwardIterator first, ForwardIterator last,  bool icase = false) const;
// Returns: An unspecified value that represents the character classification named by the character sequence designated by the iterator range [first,last). If the parameter icase is true then the returned mask identifies the character classification without regard to the case of the characters being matched, otherwise it does honor the case of the characters being matched.311 The value returned shall be independent of the case of the characters in the character sequence. If the name is not recognized then returns char_class_type().
// Remarks: For regex_traits<char>, at least the narrow character names in  Table 136 shall be recognized. For regex_traits<wchar_t>, at least the wide character names in Table 136 shall be recognized.
bool isctype(charT c, char_class_type f) const;
// Effects: Determines if the character c is a member of the character classification represented by f. Returns: Given the following function declaration:
// for exposition only
template<class C>
ctype_base::mask convert(typename regex_traits<C>::char_class_type f);
// that returns a value in which each ctype_base::mask value corresponding to a value in f named in Table 136 is set, then the result is determined as if by:
ctype_base::mask m = convert<charT>(f);
const ctype<charT>& ct = use_facet<ctype<charT>>(getloc());
if (ct.is(m, c)) {
    return true;
} else if (c == ct.widen('_')) {
    charT w[1] = { ct.widen('w') };
    char_class_type x = lookup_classname(w, w+1);
    return (f&x) == x;
} else {
    return false;
}
// [Example 1:
regex_traits<char> t;
string d("d");
string u("upper");
regex_traits<char>::char_class_type f;
f = t.lookup_classname(d.begin(), d.end());
// 311) For example, if the parameter icase is true then [[:lower:]] is the same as [[:alpha:]].
// Preconditions: The value of radix is 8, 10, or 16.
// Returns: The value represented by the digit ch in base radix if the character ch is a valid digit in base radix; otherwise returns -1.
f |= t.lookup_classname(u.begin(), u.end());
ctype_base::mask m = convert<char>(f); // m == ctype_base::digit|ctype_base::upper
//  [Example 2:
regex_traits<char> t;
string w("w");
regex_traits<char>::char_class_type f;
f = t.lookup_classname(w.begin(), w.end());
t.isctype('A', f);
t.isctype('_', f);
t.isctype(' ', f);
// returns true // returns true // returns false
int value(charT ch, int radix) const;
locale_type imbue(locale_type loc);
// Effects: Imbues this with a copy of the locale loc.
// [Note 1: Calling imbue with a different locale than the one currently in use invalidates all cached data held by *this.
// Postconditions: getloc() == loc.
// Returns: If no locale has been previously imbued then a copy of the global locale in effect at the time of construction of *this, otherwise a copy of the last argument passed to imbue.
locale_type getloc() const;
// Returns: If no locale has been imbued then a copy of the global locale in effect at the time of construction of *this, otherwise a copy of the last argument passed to imbue.
// Table 136: Character class names and corresponding ctype masks [tab:re.traits.classnames]
// Narrow character name Wide character name Corresponding ctype_base::mask value
// "alnum" L"alnum" ctype_base::alnum
// "alpha" L"alpha" ctype_base::alpha
// "blank" L"blank" ctype_base::blank
// "cntrl" L"cntrl" ctype_base::cntrl
// "digit" L"digit" ctype_base::digit
// "d" L"d" ctype_base::digit
// "graph" L"graph" ctype_base::graph
// "lower" L"lower" ctype_base::lower
// "print" L"print" ctype_base::print
// "punct" L"punct" ctype_base::punct
// "space" L"space" ctype_base::space
// "s" L"s" ctype_base::space
// "upper" L"upper" ctype_base::upper
// "w" L"w" ctype_base::alnum
// "xdigit" L"xdigit" ctype_base::xdigit
int main() {
    cout  <<  n4910 << endl;
    return EXIT_SUCCESS;
}

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

bash
$ clang++ p1635.cpp -std=03 -o p1635l -I. -Wall
In file included from p1635.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 \
 ^
p1635.cpp:21:19: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using char_type = charT;
                  ^
p1635.cpp:22:21: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using string_type = basic_string<char_type>;
                    ^
p1635.cpp:23:21: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using locale_type = locale;
                    ^
p1635.cpp:24:25: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using char_class_type = bitmask_type;
                        ^
p1635.cpp:47:25: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using char_class_type = bitmask_type;
                        ^
p1635.cpp:51:1: error: unknown type name 'charT'; did you mean 'char'?
charT translate(charT c) const;
^~~~~
char
p1635.cpp:51:17: error: unknown type name 'charT'; did you mean 'char'?
charT translate(charT c) const;
                ^~~~~
                char
p1635.cpp:51:26: error: non-member function cannot have 'const' qualifier
charT translate(charT c) const;
                         ^~~~~
p1635.cpp:53:1: error: unknown type name 'charT'; did you mean 'char'?
charT translate_nocase(charT c) const;
^~~~~
char
p1635.cpp:53:24: error: unknown type name 'charT'; did you mean 'char'?
charT translate_nocase(charT c) const;
                       ^~~~~
                       char
p1635.cpp:53:33: error: non-member function cannot have 'const' qualifier
charT translate_nocase(charT c) const;
                                ^~~~~
p1635.cpp:56:68: error: non-member function cannot have 'const' qualifier
string_type transform(ForwardIterator first, ForwardIterator last) const;
                                                                   ^~~~~
p1635.cpp:58:24: error: unknown type name 'first'
       string_type str(first, last);
                       ^
p1635.cpp:58:31: error: unknown type name 'last'
       string_type str(first, last);
                              ^
p1635.cpp:59:8: error: expected unqualified-id
       return use_facet<collate<charT>>(
       ^
p1635.cpp:62:78: error: non-member function cannot have 'const' qualifier
  string_type transform_primary(ForwardIterator first, ForwardIterator last) const;
                                                                             ^~~~~
p1635.cpp:65:79: error: non-member function cannot have 'const' qualifier
  string_type lookup_collatename(ForwardIterator first, ForwardIterator last) const;
                                                                              ^~~~~
p1635.cpp:68:103: error: non-member function cannot have 'const' qualifier
  char_class_type lookup_classname( ForwardIterator first, ForwardIterator last,  bool icase = false) const;
                                                                                                      ^~~~~
p1635.cpp:71:14: error: unknown type name 'charT'; did you mean 'char'?
bool isctype(charT c, char_class_type f) const;
             ^~~~~
             char
p1635.cpp:71:42: error: non-member function cannot have 'const' qualifier
bool isctype(charT c, char_class_type f) const;
                                         ^~~~~
p1635.cpp:77:37: error: use of undeclared identifier 'charT'; did you mean 'char'?
       ctype_base::mask m = convert<charT>(f);
                                    ^~~~~
                                    char
p1635.cpp:77:44: error: use of undeclared identifier 'f'
       ctype_base::mask m = convert<charT>(f);
                                           ^
p1635.cpp:78:20: error: use of undeclared identifier 'charT'; did you mean 'char'?
       const ctype<charT>& ct = use_facet<ctype<charT>>(getloc());
                   ^~~~~
                   char
fatal error: too many errors emitted, stopping now [-ferror-limit=]
5 warnings and 20 errors generated.
$ clang++ p1635.cpp -std=2b -o p1635l -I. -Wall
p1635.cpp:51:1: error: unknown type name 'charT'; did you mean 'char'?
charT translate(charT c) const;
^~~~~
char
p1635.cpp:51:17: error: unknown type name 'charT'; did you mean 'char'?
charT translate(charT c) const;
                ^~~~~
                char
p1635.cpp:51:26: error: non-member function cannot have 'const' qualifier
charT translate(charT c) const;
                         ^~~~~
p1635.cpp:53:1: error: unknown type name 'charT'; did you mean 'char'?
charT translate_nocase(charT c) const;
^~~~~
char
p1635.cpp:53:24: error: unknown type name 'charT'; did you mean 'char'?
charT translate_nocase(charT c) const;
                       ^~~~~
                       char
p1635.cpp:53:33: error: non-member function cannot have 'const' qualifier
charT translate_nocase(charT c) const;
                                ^~~~~
p1635.cpp:56:68: error: non-member function cannot have 'const' qualifier
string_type transform(ForwardIterator first, ForwardIterator last) const;
                                                                   ^~~~~
p1635.cpp:58:24: error: unknown type name 'first'
       string_type str(first, last);
                       ^
p1635.cpp:58:31: error: unknown type name 'last'
       string_type str(first, last);
                              ^
p1635.cpp:59:8: error: expected unqualified-id
       return use_facet<collate<charT>>(
       ^
p1635.cpp:62:78: error: non-member function cannot have 'const' qualifier
  string_type transform_primary(ForwardIterator first, ForwardIterator last) const;
                                                                             ^~~~~
p1635.cpp:65:79: error: non-member function cannot have 'const' qualifier
  string_type lookup_collatename(ForwardIterator first, ForwardIterator last) const;
                                                                              ^~~~~
p1635.cpp:68:103: error: non-member function cannot have 'const' qualifier
  char_class_type lookup_classname( ForwardIterator first, ForwardIterator last,  bool icase = false) const;
                                                                                                      ^~~~~
p1635.cpp:71:14: error: unknown type name 'charT'; did you mean 'char'?
bool isctype(charT c, char_class_type f) const;
             ^~~~~
             char
p1635.cpp:71:42: error: non-member function cannot have 'const' qualifier
bool isctype(charT c, char_class_type f) const;
                                         ^~~~~
p1635.cpp:77:37: error: use of undeclared identifier 'charT'; did you mean 'char'?
       ctype_base::mask m = convert<charT>(f);
                                    ^~~~~
                                    char
p1635.cpp:77:44: error: use of undeclared identifier 'f'
       ctype_base::mask m = convert<charT>(f);
                                           ^
p1635.cpp:78:20: error: use of undeclared identifier 'charT'; did you mean 'char'?
       const ctype<charT>& ct = use_facet<ctype<charT>>(getloc());
                   ^~~~~
                   char
p1635.cpp:78:49: error: use of undeclared identifier 'charT'; did you mean 'char'?
       const ctype<charT>& ct = use_facet<ctype<charT>>(getloc());
                                                ^~~~~
                                                char
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.

$ g++ p1635.cpp -std=03 -o p1635g -I. -Wall
In file included from /usr/local/include/c++/12.1.0/atomic:38,
                 from N4910.h:11,
                 from p1635.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 \
      |  ^~~~~
p1635.cpp:21:7: error: expected nested-name-specifier before 'char_type'
   21 | using char_type = charT;
      |       ^~~~~~~~~
p1635.cpp:22:7: error: expected nested-name-specifier before 'string_type'
   22 | using string_type = basic_string<char_type>;
      |       ^~~~~~~~~~~
p1635.cpp:23:7: error: expected nested-name-specifier before 'locale_type'
   23 | using locale_type = locale;
      |       ^~~~~~~~~~~
p1635.cpp:24:7: error: expected nested-name-specifier before 'char_class_type'
   24 | using char_class_type = bitmask_type;
      |       ^~~~~~~~~~~~~~~
p1635.cpp:38:3: error: 'char_class_type' does not name a type
   38 |   char_class_type lookup_classname(
      |   ^~~~~~~~~~~~~~~
p1635.cpp:40:23: error: 'char_class_type' has not been declared
   40 | bool isctype(charT c, char_class_type f) const;
      |                       ^~~~~~~~~~~~~~~
p1635.cpp:42:1: error: 'locale_type' does not name a type; did you mean 'locale_t'?
   42 | locale_type imbue(locale_type l);
      | ^~~~~~~~~~~
      | locale_t
p1635.cpp:43:1: error: 'locale_type' does not name a type; did you mean 'locale_t'?
   43 | locale_type getloc() const;
      | ^~~~~~~~~~~
      | locale_t
p1635.cpp:47:7: error: expected nested-name-specifier before 'char_class_type'
   47 | using char_class_type = bitmask_type;
      |       ^~~~~~~~~~~~~~~
p1635.cpp:51:1: error: 'charT' does not name a type; did you mean 'char'?
   51 | charT translate(charT c) const;
      | ^~~~~
      | char
p1635.cpp:53:1: error: 'charT' does not name a type; did you mean 'char'?
   53 | charT translate_nocase(charT c) const;
      | ^~~~~
      | char
p1635.cpp:56:68: error: non-member function 'string_type transform(ForwardIterator, ForwardIterator)' cannot have cv-qualifier
   56 | string_type transform(ForwardIterator first, ForwardIterator last) const;
      |                                                                    ^~~~~
p1635.cpp:58:24: error: 'first' was not declared in this scope
   58 |        string_type str(first, last);
      |                        ^~~~~
p1635.cpp:58:31: error: 'last' was not declared in this scope
   58 |        string_type str(first, last);
      |                               ^~~~
p1635.cpp:59:8: error: expected unqualified-id before 'return'
   59 |        return use_facet<collate<charT>>(
      |        ^~~~~~
p1635.cpp:62:78: error: non-member function 'string_type transform_primary(ForwardIterator, ForwardIterator)' cannot have cv-qualifier
   62 |   string_type transform_primary(ForwardIterator first, ForwardIterator last) const;
      |                                                                              ^~~~~
p1635.cpp:65:79: error: non-member function 'string_type lookup_collatename(ForwardIterator, ForwardIterator)' cannot have cv-qualifier
   65 |   string_type lookup_collatename(ForwardIterator first, ForwardIterator last) const;
      |                                                                               ^~~~~
p1635.cpp:68:3: error: 'char_class_type' does not name a type
   68 |   char_class_type lookup_classname( ForwardIterator first, ForwardIterator last,  bool icase = false) const;
      |   ^~~~~~~~~~~~~~~
p1635.cpp:71:14: error: 'bool isctype' redeclared as different kind of entity
   71 | bool isctype(charT c, char_class_type f) const;
      |              ^~~~~
In file included from /usr/local/include/c++/12.1.0/cctype:42,
                 from /usr/local/include/c++/12.1.0/bits/localefwd.h:42,
                 from /usr/local/include/c++/12.1.0/ios:41,
                 from /usr/local/include/c++/12.1.0/ostream:38,
                 from /usr/local/include/c++/12.1.0/iostream:39,
                 from N4910.h:2:
/usr/include/ctype.h:135:12: note: previous declaration 'int isctype(int, int)'
  135 | extern int isctype (int __c, int __mask) __THROW;
      |            ^~~~~~~
p1635.cpp:71:14: error: 'charT' was not declared in this scope; did you mean 'char'?
   71 | bool isctype(charT c, char_class_type f) const;
      |              ^~~~~
      |              char
p1635.cpp:71:23: error: 'char_class_type' was not declared in this scope
   71 | bool isctype(charT c, char_class_type f) const;
      |                       ^~~~~~~~~~~~~~~
p1635.cpp:77:37: error: 'charT' was not declared in this scope; did you mean 'char'?
   77 |        ctype_base::mask m = convert<charT>(f);
      |                                     ^~~~~
      |                                     char
p1635.cpp:77:44: error: 'f' was not declared in this scope
   77 |        ctype_base::mask m = convert<charT>(f);
      |                                            ^
p1635.cpp:78:20: error: 'charT' was not declared in this scope; did you mean 'char'?
   78 |        const ctype<charT>& ct = use_facet<ctype<charT>>(getloc());
      |                    ^~~~~
      |                    char
p1635.cpp:78:25: error: template argument 1 is invalid
   78 |        const ctype<charT>& ct = use_facet<ctype<charT>>(getloc());
      |                         ^
p1635.cpp:78:49: error: 'charT' was not declared in this scope; did you mean 'char'?
   78 |        const ctype<charT>& ct = use_facet<ctype<charT>>(getloc());
      |                                                 ^~~~~
      |                                                 char
p1635.cpp:78:54: warning: '>>' operator is treated as two right angle brackets in C++11 [-Wc++11-compat]
   78 |        const ctype<charT>& ct = use_facet<ctype<charT>>(getloc());
      |                                                      ^~
p1635.cpp:78:54: note: suggest parentheses around '>>' expression
p1635.cpp:78:64: error: a function call cannot appear in a constant-expression
   78 |        const ctype<charT>& ct = use_facet<ctype<charT>>(getloc());
      |                                                                ^
p1635.cpp:78:65: error: template argument 1 is invalid
   78 |        const ctype<charT>& ct = use_facet<ctype<charT>>(getloc());
      |                                                                 ^
p1635.cpp:78:33: error: parse error in template argument list
   78 |        const ctype<charT>& ct = use_facet<ctype<charT>>(getloc());
      |                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
p1635.cpp:78:33: error: invalid initialization of reference of type 'const int&' from expression of type '<unresolved overloaded function type>'
p1635.cpp:79:8: error: expected unqualified-id before 'if'
   79 |        if (ct.is(m, c)) {
      |        ^~
p1635.cpp:81:10: error: expected unqualified-id before 'else'
   81 |        } else if (c == ct.widen('_')) {
      |          ^~~~
p1635.cpp:85:10: error: expected unqualified-id before 'else'
   85 |        } else {
      |          ^~~~
p1635.cpp:92:28: error: 'char_class_type' in 'struct std::regex_traits<char>' does not name a type
   92 |        regex_traits<char>::char_class_type f;
      |                            ^~~~~~~~~~~~~~~
p1635.cpp:93:8: error: 'f' does not name a type
   93 |        f = t.lookup_classname(d.begin(), d.end());
      |        ^
p1635.cpp:97:1: error: 'f' does not name a type
   97 | f |= t.lookup_classname(u.begin(), u.end());
      | ^
p1635.cpp:98:18: error: redefinition of 'std::ctype_base::mask m'
   98 | ctype_base::mask m = convert<char>(f); // m == ctype_base::digit|ctype_base::upper
      |                  ^
p1635.cpp:77:25: note: 'std::ctype_base::mask m' previously defined here
   77 |        ctype_base::mask m = convert<charT>(f);
      |                         ^
p1635.cpp:98:36: error: 'f' was not declared in this scope
   98 | ctype_base::mask m = convert<char>(f); // m == ctype_base::digit|ctype_base::upper
      |                                    ^
p1635.cpp:100:22: error: redefinition of 'std::regex_traits<char> t'
  100 |   regex_traits<char> t;
      |                      ^
p1635.cpp:89:27: note: 'std::regex_traits<char> t' previously declared here
   89 |        regex_traits<char> t;
      |                           ^
p1635.cpp:102:23: error: 'char_class_type' in 'struct std::regex_traits<char>' does not name a type
  102 |   regex_traits<char>::char_class_type f;
      |                       ^~~~~~~~~~~~~~~
p1635.cpp:103:3: error: 'f' does not name a type
  103 |   f = t.lookup_classname(w.begin(), w.end());
      |   ^
p1635.cpp:104:3: error: 't' does not name a type; did you mean 'tm'?
  104 |   t.isctype('A', f);
      |   ^
      |   tm
p1635.cpp:105:3: error: 't' does not name a type; did you mean 'tm'?
  105 |   t.isctype('_', f);
      |   ^
      |   tm
p1635.cpp:106:3: error: 't' does not name a type; did you mean 'tm'?
  106 |   t.isctype(' ', f);
      |   ^
      |   tm
p1635.cpp:108:11: error: 'charT' was not declared in this scope; did you mean 'char'?
  108 | int value(charT ch, int radix) const;
      |           ^~~~~
      |           char
p1635.cpp:108:21: error: expected primary-expression before 'int'
  108 | int value(charT ch, int radix) const;
      |                     ^~~
p1635.cpp:108:30: error: expression list treated as compound expression in initializer [-fpermissive]
  108 | int value(charT ch, int radix) const;
      |                              ^
p1635.cpp:109:1: error: 'locale_type' does not name a type; did you mean 'locale_t'?
  109 | locale_type imbue(locale_type loc);
      | ^~~~~~~~~~~
      | locale_t
p1635.cpp:114:1: error: 'locale_type' does not name a type; did you mean 'locale_t'?
  114 | locale_type getloc() const;
      | ^~~~~~~~~~~
      | locale_t
p1635.cpp:49:15: warning: 'size_t length(const char_type*)' declared 'static' but never defined [-Wunused-function]
   49 | static size_t length(const char_type* p);
      |               ^~~~~~

$ g++ p1635.cpp -std=2b -o p1635g -I. -Wall
p1635.cpp:51:1: error: 'charT' does not name a type; did you mean 'char'?
   51 | charT translate(charT c) const;
      | ^~~~~
      | char
p1635.cpp:53:1: error: 'charT' does not name a type; did you mean 'char'?
   53 | charT translate_nocase(charT c) const;
      | ^~~~~
      | char
p1635.cpp:56:68: error: non-member function 'string_type transform(ForwardIterator, ForwardIterator)' cannot have cv-qualifier
   56 | string_type transform(ForwardIterator first, ForwardIterator last) const;
      |                                                                    ^~~~~
p1635.cpp:58:24: error: 'first' was not declared in this scope
   58 |        string_type str(first, last);
      |                        ^~~~~
p1635.cpp:58:31: error: 'last' was not declared in this scope
   58 |        string_type str(first, last);
      |                               ^~~~
p1635.cpp:59:8: error: expected unqualified-id before 'return'
   59 |        return use_facet<collate<charT>>(
      |        ^~~~~~
p1635.cpp:62:78: error: non-member function 'string_type transform_primary(ForwardIterator, ForwardIterator)' cannot have cv-qualifier
   62 |   string_type transform_primary(ForwardIterator first, ForwardIterator last) const;
      |                                                                              ^~~~~
p1635.cpp:65:79: error: non-member function 'string_type lookup_collatename(ForwardIterator, ForwardIterator)' cannot have cv-qualifier
   65 |   string_type lookup_collatename(ForwardIterator first, ForwardIterator last) const;
      |                                                                               ^~~~~
p1635.cpp:68:103: error: non-member function 'char_class_type lookup_classname(ForwardIterator, ForwardIterator, bool)' cannot have cv-qualifier
   68 |   char_class_type lookup_classname( ForwardIterator first, ForwardIterator last,  bool icase = false) const;
      |                                                                                                       ^~~~~
p1635.cpp:71:14: error: 'bool isctype' redeclared as different kind of entity
   71 | bool isctype(charT c, char_class_type f) const;
      |              ^~~~~
In file included from /usr/local/include/c++/12.1.0/cctype:42,
                 from /usr/local/include/c++/12.1.0/bits/localefwd.h:42,
                 from /usr/local/include/c++/12.1.0/ios:41,
                 from /usr/local/include/c++/12.1.0/ostream:38,
                 from /usr/local/include/c++/12.1.0/iostream:39,
                 from N4910.h:2,
                 from p1635.cpp:10:
/usr/include/ctype.h:135:12: note: previous declaration 'int isctype(int, int)'
  135 | extern int isctype (int __c, int __mask) __THROW;
      |            ^~~~~~~
p1635.cpp:71:14: error: 'charT' was not declared in this scope; did you mean 'char'?
   71 | bool isctype(charT c, char_class_type f) const;
      |              ^~~~~
      |              char
p1635.cpp:71:39: error: expected primary-expression before 'f'
   71 | bool isctype(charT c, char_class_type f) const;
      |                                       ^
p1635.cpp:77:37: error: 'charT' was not declared in this scope; did you mean 'char'?
   77 |        ctype_base::mask m = convert<charT>(f);
      |                                     ^~~~~
      |                                     char
p1635.cpp:77:44: error: 'f' was not declared in this scope
   77 |        ctype_base::mask m = convert<charT>(f);
      |                                            ^
p1635.cpp:78:20: error: 'charT' was not declared in this scope; did you mean 'char'?
   78 |        const ctype<charT>& ct = use_facet<ctype<charT>>(getloc());
      |                    ^~~~~
      |                    char
p1635.cpp:78:25: error: template argument 1 is invalid
   78 |        const ctype<charT>& ct = use_facet<ctype<charT>>(getloc());
      |                         ^
p1635.cpp:78:49: error: 'charT' was not declared in this scope; did you mean 'char'?
   78 |        const ctype<charT>& ct = use_facet<ctype<charT>>(getloc());
      |                                                 ^~~~~
      |                                                 char
p1635.cpp:78:49: error: template argument 1 is invalid
p1635.cpp:78:57: error: 'getloc' was not declared in this scope; did you mean 'getwc'?
   78 |        const ctype<charT>& ct = use_facet<ctype<charT>>(getloc());
      |                                                         ^~~~~~
      |                                                         getwc
p1635.cpp:79:8: error: expected unqualified-id before 'if'
   79 |        if (ct.is(m, c)) {
      |        ^~
p1635.cpp:81:10: error: expected unqualified-id before 'else'
   81 |        } else if (c == ct.widen('_')) {
      |          ^~~~
p1635.cpp:85:10: error: expected unqualified-id before 'else'
   85 |        } else {
      |          ^~~~
p1635.cpp:93:8: error: 'f' does not name a type
   93 |        f = t.lookup_classname(d.begin(), d.end());
      |        ^
p1635.cpp:97:1: error: 'f' does not name a type
   97 | f |= t.lookup_classname(u.begin(), u.end());
      | ^
p1635.cpp:98:18: error: redefinition of 'std::ctype_base::mask m'
   98 | ctype_base::mask m = convert<char>(f); // m == ctype_base::digit|ctype_base::upper
      |                  ^
p1635.cpp:77:25: note: 'std::ctype_base::mask m' previously defined here
   77 |        ctype_base::mask m = convert<charT>(f);
      |                         ^
p1635.cpp:100:22: error: redefinition of 'std::regex_traits<char> t'
  100 |   regex_traits<char> t;
      |                      ^
p1635.cpp:89:27: note: 'std::regex_traits<char> t' previously declared here
   89 |        regex_traits<char> t;
      |                           ^
p1635.cpp:102:39: error: redefinition of 'std::regex_traits<char>::char_class_type f'
  102 |   regex_traits<char>::char_class_type f;
      |                                       ^
p1635.cpp:92:44: note: 'std::regex_traits<char>::char_class_type f' previously declared here
   92 |        regex_traits<char>::char_class_type f;
      |                                            ^
p1635.cpp:103:3: error: 'f' does not name a type
  103 |   f = t.lookup_classname(w.begin(), w.end());
      |   ^
p1635.cpp:104:3: error: 't' does not name a type; did you mean 'tm'?
  104 |   t.isctype('A', f);
      |   ^
      |   tm
p1635.cpp:105:3: error: 't' does not name a type; did you mean 'tm'?
  105 |   t.isctype('_', f);
      |   ^
      |   tm
p1635.cpp:106:3: error: 't' does not name a type; did you mean 'tm'?
  106 |   t.isctype(' ', f);
      |   ^
      |   tm
p1635.cpp:108:11: error: 'charT' was not declared in this scope; did you mean 'char'?
  108 | int value(charT ch, int radix) const;
      |           ^~~~~
      |           char
p1635.cpp:108:21: error: expected primary-expression before 'int'
  108 | int value(charT ch, int radix) const;
      |                     ^~~
p1635.cpp:108:30: error: expression list treated as compound expression in initializer [-fpermissive]
  108 | int value(charT ch, int radix) const;
      |                              ^
p1635.cpp:109:1: error: 'locale_type' does not name a type; did you mean 'locale_t'?
  109 | locale_type imbue(locale_type loc);
      | ^~~~~~~~~~~
      | locale_t
p1635.cpp:114:1: error: 'locale_type' does not name a type; did you mean 'locale_t'?
  114 | locale_type getloc() const;
      | ^~~~~~~~~~~
      | locale_t
p1635.cpp:49:15: warning: 'size_t length(const char_type*)' declared 'static' but never defined [-Wunused-function]
   49 | static size_t length(const char_type* p);
      |               ^~~~~~

検討事項(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 箱庭 

箱庭もくもく会

第11回 未定

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

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

この項目は、箱庭プロジェクトを市場分析の対象として、原則的には、箱庭プロジェクトの外部から分析し、外部から箱庭の広告宣伝のための戦略会議を仮想した結果、仮想「箱庭もくもく会」を開催してみることを企画するものである。 
一切の内容は、箱庭プロジェクト、Athrill, TOPPERSとは無関係である。 
一(いち)参加データアナリストの、個人的なつぶやきです。

仮想戦略会議「箱庭」

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

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

自己参考資料(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 初稿  20220920

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?