7

次のコードが c++11 標準に従って有効であり、異なる実装間で同じ動作をする必要があるかどうかはわかりません。

#include <cstddef>
struct Foo{
    template <std::size_t N>
    constexpr Foo( const char ( &other )[N] )       
    {}

    template <class T>
    constexpr Foo( const  T* const& other ) = delete;
};

struct Bar {
    Foo a;
    int b;
};

int main() {
    Bar bar{ "Hello",5};
}

一般的なアイデアは、文字列リテラルと a std::string(ここには示されていません) からの構築を許可することですが、 へのポインターからconst char構築は許可しません。

g++ の新しいバージョン (>=6.0) とほとんどすべての clang++ バージョン (>=3.4) はこれをうまくコンパイルしているようですが、たとえば g++-4.8 -std=c++11 main.cpp、次のエラーが発生します。

main.cpp: In function ‘int main()’:
main.cpp:17:27: error: use of deleted function ‘constexpr Foo::Foo(const T* const&) [with T = char]’
     Bar bar{ "Hello",5};

したがって、私の質問は次
のとおりです 。標準では、このコードに対して特定の動作が必要ですか?もしそうなら、誰が正しいですか?

4

1 に答える 1