2010-03-11

文字列リテラルに関するドラフトの間違い

規格上に、文字列リテラルを、non-constなchar *に代入しているサンプルコードがある。

8.5.1 Aggregates [dcl.init.aggr] p7

struct S { int a; char* b; int c; };
S ss = { 1, "asdf" };

8.5.1 Aggregates [dcl.init.aggr] p15
エラーとなっているが、unionへの代入に対するエラーで、文字列リテラルのconst性は意図していない。

union u { int a; char* b; };
u a = { 1 };
u b = a;
u c = 1; // error
u d = { 0, "asdf" }; // error
u e = { "asdf" }; // error

9.3.1 Nonstatic member functions [class.mfct.non-static] p3

struct tnode {
//...
void set(char*, tnode* l, tnode* r);
};

//...

void f(tnode n1, tnode n2) {
n1.set("abc",&n2,0);
n2.set("def",0,0);
}

9.5 Unions [class.union] p2

void f() {
union { int a; char* p; };
a = 1;
p = "Jennifer";
}

13.2 Declaration matching [over.dcl] p1

//...
struct D : B {
int f(char*);
};

//...

void h(D* pd) {
//...
pd->f("Ben"); // OK, calls D::f
}

13.2 Declaration matching [over.dcl] p2

void f(char*);
void g() {
extern void f(int);
f("asdf"); // error: f(int) hides f(char*)
// so there is no f(char*) in this scope
}

13.3.1.2 Operators in expressions [over.match.oper] p1

struct String {
String (const String&);
String (char*);
operator char* ();
};
String operator + (const String&, const String&);
void f(void) {
char* p= "one" + "two"; // ill-formed because neither
//...
}

14.4.2 Template non-type arguments [temp.arg.nontype] p2
これは微妙かもしれない。そもそもエラーを示す目的なのだから。

template<class T, char* p> class X {
X();
X(const char* q) { /  ...  / }
};
X<int, "Studebaker"> x1; // error: string literal as template-argument
char p[] = "Vivisectionist";

14.8.1 Implicit instantiation [temp.inst] p10

namespace N {
template<class T> class List {
public:
T* get();
};
}
template<class K, class V> class Map {
public:
N::List<V> lt;
V get(K);
};
void g(Map<char*,int>& m) {
int

14.9.1 Explicit template argument specification [temp.arg.explicit] p5

template<class X, class Y, class Z> X f(Y,Z);
template<class ... Args> void f2();
void g() {
f<int,char*,double>("aa",3.0);
f<int,char*>("aa",3.0); // Z is deduced to be double
f<int>("aa",3.0); // Y is deduced to be const char*, and
// Z is deduced to be double
f("aa",3.0); // error: X cannot be deduced
f2<char, short, int, long>(); // OK
}

ついでに、こんな間違いもあった。報告しておかないと。

5 Expressions [expr] p6
rvalue referenceをlvalueで初期化している。

struct A { };
A&& operator+(A, A);
A&& f();
A a;
A&& ar = a;

No comments:

Post a Comment

You can use some HTML elements, such as <b>, <i>, <a>, also, some characters need to be entity referenced such as <, > and & Your comment may need to be confirmed by blog author. Your comment will be published under GFDL 1.3 or later license with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.