Skip to content

Commit

Permalink
[std] Harmonize comments indicating errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
jensmaurer committed Dec 19, 2019
1 parent af31580 commit 868a76b
Show file tree
Hide file tree
Showing 13 changed files with 151 additions and 153 deletions.
28 changes: 14 additions & 14 deletions source/basic.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1012,10 +1012,10 @@
\begin{example}
\begin{codeblock}
if (int x = f()) {
int x; // ill-formed, redeclaration of \tcode{x}
int x; // error: redeclaration of \tcode{x}
}
else {
int x; // ill-formed, redeclaration of \tcode{x}
int x; // error: redeclaration of \tcode{x}
}
\end{codeblock}
\end{example}
Expand Down Expand Up @@ -1958,9 +1958,9 @@
}
void test() {
auto x = make(); // OK, \tcode{decltype(x)} is \tcode{R::X} in module \tcode{M}
R::f(x); // ill-formed: \tcode{R} and \tcode{R::f} are not visible here
R::f(x); // error: \tcode{R} and \tcode{R::f} are not visible here
f(x); // OK, calls \tcode{R::f} from interface of \tcode{M}
f(x, S::Z()); // ill-formed: \tcode{S::f} in module \tcode{M} not considered
f(x, S::Z()); // error: \tcode{S::f} in module \tcode{M} not considered
// even though \tcode{S} is an associated namespace
apply(x, S::Z()); // OK, \tcode{S::f} is visible in instantiation context, and
// \tcode{R::g} is visible even though it has internal linkage
Expand Down Expand Up @@ -1996,7 +1996,7 @@
int main() {
int A;
A::n = 42; // OK
A b; // ill-formed: \tcode{A} does not name a type
A b; // error: \tcode{A} does not name a type
}
\end{codeblock}
\end{example}
Expand All @@ -2022,7 +2022,7 @@
static const int number = 50;
static X arr[number];
};
X C::arr[number]; // ill-formed:
X C::arr[number]; // error:
// equivalent to \tcode{::X} \tcode{C::arr[C::number];}
// and not to \tcode{C::X} \tcode{C::arr[C::number];}
\end{codeblock}
Expand Down Expand Up @@ -2149,7 +2149,7 @@
B::B() { }

B::A ba; // object of type \tcode{A}
A::A a; // error, \tcode{A::A} is not a type name
A::A a; // error: \tcode{A::A} is not a type name
struct A::A a2; // object of type \tcode{A}
\end{codeblock}
\end{example}
Expand Down Expand Up @@ -2371,7 +2371,7 @@
}
using namespace B;
}
void A::f1(int){ } // ill-formed, \tcode{f1} is not a member of \tcode{A}
void A::f1(int){ } // error: \tcode{f1} is not a member of \tcode{A}
\end{codeblock}
\end{example}
However, in such namespace member declarations, the
Expand Down Expand Up @@ -3288,7 +3288,7 @@
pb->mutate();
*pb; // OK: \tcode{pb} points to valid memory
void* q = pb; // OK: \tcode{pb} points to valid memory
pb->f(); // undefined behavior, lifetime of \tcode{*pb} has ended
pb->f(); // undefined behavior: lifetime of \tcode{*pb} has ended
}
\end{codeblock}
\end{example}
Expand Down Expand Up @@ -4533,8 +4533,8 @@
UNKA** arrpp;

void foo() {
xp++; // ill-formed: \tcode{X} is incomplete
arrp++; // ill-formed: incomplete type
xp++; // error: \tcode{X} is incomplete
arrp++; // error: incomplete type
arrpp++; // OK: sizeof \tcode{UNKA*} is known
}

Expand All @@ -4544,9 +4544,9 @@
X x;
void bar() {
xp = &x; // OK; type is ``pointer to \tcode{X}''
arrp = &arr; // ill-formed: different types
arrp = &arr; // error: different types
xp++; // OK: \tcode{X} is complete
arrp++; // ill-formed: \tcode{UNKA} can't be completed
arrp++; // error: \tcode{UNKA} can't be completed
}
\end{codeblock}
\end{example}
Expand Down Expand Up @@ -5464,7 +5464,7 @@
i = 7, i++, i++; // \tcode{i} becomes \tcode{9}

i = i++ + 1; // the value of \tcode{i} is incremented
i = i++ + i; // the behavior is undefined
i = i++ + i; // undefined behavior
i = i + 1; // the value of \tcode{i} is incremented
}
\end{codeblock}
Expand Down
66 changes: 33 additions & 33 deletions source/classes.tex
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@
simply a single function \tcode{f()} twice. For the same reason,
\begin{codeblock}
struct S { int a; };
struct S { int a; }; // error, double definition
struct S { int a; }; // error: double definition
\end{codeblock}
is ill-formed because it defines \tcode{S} twice.
\end{example}
Expand Down Expand Up @@ -2477,7 +2477,7 @@
};

Y a;
int b = a; // error, \tcode{a.operator X().operator int()} not tried
int b = a; // error: no viable conversion (\tcode{a.operator X().operator int()} not considered)
int c = X(a); // OK: \tcode{a.operator X().operator int()}
\end{codeblock}
\end{example}
Expand All @@ -2500,7 +2500,7 @@
};

void f(Y& a) {
if (a) { // ill-formed: \tcode{X::operator int()} or \tcode{Y::operator char()}
if (a) { // error: ambiguous between \tcode{X::operator int()} and \tcode{Y::operator char()}
}
}
\end{codeblock}
Expand Down Expand Up @@ -2643,7 +2643,7 @@

void h(Z z) {
Y y1(z); // OK: direct-initialization
Y y2 = z; // ill-formed: copy-initialization
Y y2 = z; // error: no conversion function candidate for copy-initialization
Y y3 = (Y)z; // OK: cast notation
}

Expand Down Expand Up @@ -3615,7 +3615,7 @@
\begin{example}
\begin{codeblock}
class X { @\commentellip@ };
class Y : public X, public X { @\commentellip@ }; // ill-formed
class Y : public X, public X { @\commentellip@ }; // error

\end{codeblock}
\begin{codeblock}
Expand Down Expand Up @@ -3931,7 +3931,7 @@
Derived* dp = &d;
D* q = dp->vf4(); // calls \tcode{Derived::vf4()} and does not
// convert the result to \tcode{B*}
dp->vf2(); // ill-formed: argument mismatch
dp->vf2(); // error: argument mismatch
}
\end{codeblock}
\end{example}
Expand Down Expand Up @@ -3989,7 +3989,7 @@
A* ap = b1p;
D* dp = &d;
ap->f(); // calls \tcode{D::B1::f}
dp->f(); // ill-formed: ambiguous
dp->f(); // error: ambiguous
}
\end{codeblock}
In class \tcode{D} above there are two occurrences of class \tcode{A}
Expand All @@ -4015,7 +4015,7 @@
void f();
};

struct Error : VB1, VB2 { // ill-formed
struct Error : VB1, VB2 { // error
};

struct Okay : VB1, VB2 {
Expand Down Expand Up @@ -4130,7 +4130,7 @@
\begin{example}
\begin{codeblock}
struct C {
virtual void f() = 0 { }; // ill-formed
virtual void f() = 0 { }; // error
};
\end{codeblock}
\end{example}
Expand Down Expand Up @@ -4349,7 +4349,7 @@
pd->v++; // OK: only one \tcode{v} (virtual)
pd->s++; // OK: only one \tcode{s} (static)
int i = pd->e; // OK: only one \tcode{e} (enumerator)
pd->a++; // error, ambiguous: two \tcode{a}{s} in \tcode{D}
pd->a++; // error: ambiguous: two \tcode{a}{s} in \tcode{D}
}
\end{codeblock}
\end{example}
Expand Down Expand Up @@ -4414,7 +4414,7 @@
void g() {
D d;
B* pb = &d;
A* pa = &d; // error, ambiguous: \tcode{C}'s \tcode{A} or \tcode{B}'s \tcode{A}?
A* pa = &d; // error: ambiguous: \tcode{C}'s \tcode{A} or \tcode{B}'s \tcode{A}?
V* pv = &d; // OK: only one \tcode{V} subobject
}
\end{codeblock}
Expand Down Expand Up @@ -5273,7 +5273,7 @@
friend void c(); // error
};
X* px; // OK, but \tcode{::X} is found
Z* pz; // error, no \tcode{Z} is found
Z* pz; // error: no \tcode{Z} is found
}
\end{codeblock}
\end{example}
Expand Down Expand Up @@ -5311,31 +5311,31 @@
};

void fr(B* pb, D1* p1, D2* p2) {
pb->i = 1; // ill-formed
p1->i = 2; // ill-formed
pb->i = 1; // error
p1->i = 2; // error
p2->i = 3; // OK (access through a \tcode{D2})
p2->B::i = 4; // OK (access through a \tcode{D2}, even though naming class is \tcode{B})
int B::* pmi_B = &B::i; // ill-formed
int B::* pmi_B = &B::i; // error
int B::* pmi_B2 = &D2::i; // OK (type of \tcode{\&D2::i} is \tcode{int B::*})
B::j = 5; // ill-formed (not a friend of naming class \tcode{B})
B::j = 5; // error: not a friend of naming class \tcode{B}
D2::j = 6; // OK (because refers to static member)
}

void D2::mem(B* pb, D1* p1) {
pb->i = 1; // ill-formed
p1->i = 2; // ill-formed
pb->i = 1; // error
p1->i = 2; // error
i = 3; // OK (access through \tcode{this})
B::i = 4; // OK (access through \tcode{this}, qualification ignored)
int B::* pmi_B = &B::i; // ill-formed
int B::* pmi_B = &B::i; // error
int B::* pmi_B2 = &D2::i; // OK
j = 5; // OK (because \tcode{j} refers to static member)
B::j = 6; // OK (because \tcode{B::j} refers to static member)
}

void g(B* pb, D1* p1, D2* p2) {
pb->i = 1; // ill-formed
p1->i = 2; // ill-formed
p2->i = 3; // ill-formed
pb->i = 1; // error
p1->i = 2; // error
p2->i = 3; // error
}
\end{codeblock}
\end{example}
Expand Down Expand Up @@ -5660,7 +5660,7 @@
struct A { A(); };
struct B: public virtual A { };
struct C: public A, public B { C(); };
C::C(): A() { } // ill-formed: which \tcode{A}?
C::C(): A() { } // error: which \tcode{A}?
\end{codeblock}
\end{example}

Expand Down Expand Up @@ -6019,7 +6019,7 @@
int j;
public:
int f();
B() : A(f()), // undefined: calls member function but base \tcode{A} not yet initialized
B() : A(f()), // undefined behavior: calls member function but base \tcode{A} not yet initialized
j(f()) { } // well-defined: bases are all initialized
};

Expand All @@ -6031,7 +6031,7 @@
class D : public B, C {
int i;
public:
D() : C(f()), // undefined: calls member function but base \tcode{C} not yet initialized
D() : C(f()), // undefined behavior: calls member function but base \tcode{C} not yet initialized
i(f()) { } // well-defined: bases are all initialized
};
\end{codeblock}
Expand Down Expand Up @@ -6153,7 +6153,7 @@
using V2::V2;
};

D1 d1(0); // ill-formed: ambiguous
D1 d1(0); // error: ambiguous
D2 d2(0); // OK: initializes virtual \tcode{B} base class, which initializes the \tcode{A} base class
// then initializes the \tcode{V1} and \tcode{V2} base classes as if by a defaulted default constructor

Expand Down Expand Up @@ -6193,10 +6193,10 @@

extern B bobj;
B* pb = &bobj; // OK
int* p1 = &bobj.a; // undefined, refers to base class member
int* p2 = &bobj.y.i; // undefined, refers to member's member
int* p1 = &bobj.a; // undefined behavior: refers to base class member
int* p2 = &bobj.y.i; // undefined behavior: refers to member's member

A* pa = &bobj; // undefined, upcast to a base class type
A* pa = &bobj; // undefined behavior: upcast to a base class type
B bobj; // definition of \tcode{bobj}

extern X xobj;
Expand Down Expand Up @@ -6285,7 +6285,7 @@
struct X { X(A*); };

struct E : C, D, X {
E() : D(this), // undefined: upcast from \tcode{E*} to \tcode{A*} might use path \tcode{E*} $\rightarrow$ \tcode{D*} $\rightarrow$ \tcode{A*}
E() : D(this), // undefined behavior: upcast from \tcode{E*} to \tcode{A*} might use path \tcode{E*} $\rightarrow$ \tcode{D*} $\rightarrow$ \tcode{A*}
// but \tcode{D} is not constructed

// ``\tcode{D((C*)this)}\!'' would be defined: \tcode{E*} $\rightarrow$ \tcode{C*} is defined because \tcode{E()} has started,
Expand Down Expand Up @@ -6343,7 +6343,7 @@
f(); // calls \tcode{V::f}, not \tcode{A::f}
g(); // calls \tcode{B::g}, not \tcode{D::g}
v->g(); // \tcode{v} is base of \tcode{B}, the call is well-defined, calls \tcode{B::g}
a->f(); // undefined behavior, \tcode{a}'s type not a base of \tcode{B}
a->f(); // undefined behavior: \tcode{a}'s type not a base of \tcode{B}
}
\end{codeblock}
\end{example}
Expand Down Expand Up @@ -6420,7 +6420,7 @@
typeid(*v); // well-defined: \tcode{*v} has type \tcode{V}, a base of \tcode{B} yields \tcode{type_info} for \tcode{B}
typeid(*a); // undefined behavior: type \tcode{A} not a base of \tcode{B}
dynamic_cast<B*>(v); // well-defined: \tcode{v} of type \tcode{V*}, \tcode{V} base of \tcode{B} results in \tcode{B*}
dynamic_cast<B*>(a); // undefined behavior, \tcode{a} has type \tcode{A*}, \tcode{A} not a base of \tcode{B}
dynamic_cast<B*>(a); // undefined behavior: \tcode{a} has type \tcode{A*}, \tcode{A} not a base of \tcode{B}
}
\end{codeblock}
\end{example}
Expand Down Expand Up @@ -6963,7 +6963,7 @@
void foo(int i) {
new (ap) D1; // calls \tcode{B::operator new(std::size_t, Arena*)}
new D1[i]; // calls \tcode{::operator new[](std::size_t)}
new D1; // ill-formed: \tcode{::operator new(std::size_t)} hidden
new D1; // error: \tcode{::operator new(std::size_t)} hidden
}
\end{codeblock}
\end{example}
Expand Down
2 changes: 1 addition & 1 deletion source/compatibility.tex
Original file line number Diff line number Diff line change
Expand Up @@ -2118,7 +2118,7 @@
int g() { return f(); }

// Translation unit 2
int f(int a = 76) { return a; } // ill-formed (no diagnostic required); previously well-formed
int f(int a = 76) { return a; } // ill-formed, no diagnostic required; previously well-formed
int g();
int main() { return g(); } // used to return 42
\end{codeblock}
Expand Down

0 comments on commit 868a76b

Please sign in to comment.