From 7f15e0b8277ac8b101b4f71ce57c1c5442927141 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 18 Mar 2023 19:51:06 +0900 Subject: fix(nuldoc): fix whitespaces being trimmed --- .../index.html | 82 +++++++++++----------- 1 file changed, 41 insertions(+), 41 deletions(-) (limited to 'public/posts/2021-10-02/cpp-you-can-use-keywords-in-attributes') diff --git a/public/posts/2021-10-02/cpp-you-can-use-keywords-in-attributes/index.html b/public/posts/2021-10-02/cpp-you-can-use-keywords-in-attributes/index.html index 74ad22d..dc9d084 100644 --- a/public/posts/2021-10-02/cpp-you-can-use-keywords-in-attributes/index.html +++ b/public/posts/2021-10-02/cpp-you-can-use-keywords-in-attributes/index.html @@ -57,18 +57,18 @@

- この記事は Qiita から移植してきたものです。 元 URL:https://qiita.com/nsfisis/items/94090937bcf860cfa93b + この記事は Qiita から移植してきたものです。 元 URL: https://qiita.com/nsfisis/items/94090937bcf860cfa93b

- +


- +

タイトル落ち。まずはこのコードを見て欲しい。

- +
#include <iostream>
 
 [[alignas]] [[alignof]] [[and]] [[and_eq]] [[asm]] [[auto]] [[bitand]]
@@ -88,105 +88,105 @@
 int main() {
 std::cout << "Hello, World!" << std::endl;
 }
- +

コンパイラのバージョン $ clang++ –version Apple clang version 11.0.0 (clang-1100.0.33.8) Target: x86_64-apple-darwin19.6.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

- +

コンパイルコマンド (C17指定) $ clang –std=c++17 hoge.cpp

- +

この記事から得られるものはこれ以上ないので以下は蛇足になる。

- +

- 別件で cppreference.com のidentifier のページを読んでいた時、次の文が目に止まった。 + 別件で cppreference.com の identifier のページ を読んでいた時、次の文が目に止まった。

- +
- +

キーワードでも属性として指定する場合は非キーワードとして使えるらしい。 実際にやってみる。

- +

- 同サイトのkeywords のページから一覧を拝借し、上のコードが出来上がった (C++17 においてキーワードでないものなど、一部省いている)。 大量の警告 (unknown attribute `〇〇' ignored) がコンパイラから出力されるが、コンパイルできる。 + 同サイトの keywords のページ から一覧を拝借し、上のコードが出来上がった (C++17 においてキーワードでないものなど、一部省いている)。 大量の警告 (unknown attribute `〇〇' ignored) がコンパイラから出力されるが、コンパイルできる。

- +

- 上のコードでは[[using]]をコメントアウトしているが、これはusingキーワードのみ属性構文の中で意味を持つからであり、このコメントアウトを外すとコンパイルに失敗する。 + 上のコードでは [[using]] をコメントアウトしているが、これは using キーワードのみ属性構文の中で意味を持つからであり、このコメントアウトを外すとコンパイルに失敗する。

- +
// using の例
 [[using foo: attr1, attr2]] int x; // [[foo::attr1, foo::attr2]] の糖衣構文
- +

C++17 の仕様も見てみる (正確には標準化前のドラフト)。

- +

- 引用元:https://timsong-cpp.github.io/cppwp/n4659/dcl.attr#grammar-4 + 引用元: https://timsong-cpp.github.io/cppwp/n4659/dcl.attr#grammar-4

- +

If a keyword or an alternative token that satisfies the syntactic requirements of an identifier is contained in an attribute-token, it is considered an identifier.

- +

- 「identifierの構文上の要件を満たすキーワードまたは代替トークンがattribute-tokenに含まれている場合、identifierとみなされる」とある。どうやら間違いないようだ。 + 「identifier の構文上の要件を満たすキーワードまたは代替トークンが attribute-token に含まれている場合、identifier とみなされる」とある。どうやら間違いないようだ。

- +

- ところで、代替トークン (alternative token) とはand(&) やbitor(|) などのことだが、identifierの構文上の要件を満たさないような代替トークンなどあるのか? 疑問に思って調べたところ、代替トークンという語にはダイグラフも含まれるらしい (参考:同ドラフト) + ところで、代替トークン (alternative token) とは and (&) や bitor (|) などのことだが、identifier の構文上の要件を満たさないような代替トークンなどあるのか? 疑問に思って調べたところ、代替トークンという語にはダイグラフも含まれるらしい (参考: 同ドラフト)

- + - +

- 「identifierの構文上の要件を満たさないような代替トークン」はこれらが当てはまると思われる。 + 「identifier の構文上の要件を満たさないような代替トークン」はこれらが当てはまると思われる。

- +

調べた感想: 字句解析器か構文解析器が辛そう

-- cgit v1.2.3-70-g09d2