【发布时间】:2019-03-01 14:50:00
【问题描述】:
我刚刚偶然发现了以下用户定义的文字:
#include <cstdint>
constexpr auto operator""_G(uint64_t v) { return v * 1'000'000'000ULL; }
但是,这不能与 GNU 7.3.0 和 -std=c++14 一起编译。我收到“有无效的参数列表”错误。
根据https://en.cppreference.com/w/cpp/language/user_literal,唯一允许的无符号64位类型是unsigned long long int。但是,stdint.h 中的 uint64_t typedef 映射到 GCC 内置定义 __UINT64_TYPE__。
#define __UINT64_TYPE__ long unsigned int;
这个定义是通过运行gcc -dM -E an_empty_file.c | grep "__UINT64_TYPE__"得到的
当然,将uint64_t 替换为unsigned long long int 可以避免编译错误。但是这两种类型在 LP64 数据模型上是相同的。
这不应该默认工作吗?
【问题讨论】:
-
static_assert(std::is_same_v<uint64_t, unsigned long long>);会触发。
标签: c++ c++14 user-defined-literals