Skip to content

Commit 7dd8fe7

Browse files
committed
minor changes to undefined behavior notes
1 parent 465a3bf commit 7dd8fe7

File tree

6 files changed

+15
-15
lines changed

6 files changed

+15
-15
lines changed

spec/arrays.dd

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,8 @@ assert(*p == 6);
4848
will be aborted.)
4949
))
5050

51-
$(UNDEFINED_BEHAVIOR
52-
$(OL
53-
$(LI Dereferencing a pointer that is not $(I null) and does not point
51+
$(UNDEFINED_BEHAVIOR dereferencing a pointer that is not $(I null) and does not point
5452
to a valid object of type $(I T).)
55-
))
5653

5754
$(P To set a pointer to point at an existing object, use the
5855
`&` *address of* operator:)

spec/const3.dd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,10 +322,10 @@ int* q = cast(int*)p;
322322
the compiler will no longer be able to statically do so.
323323
)
324324

325-
$(P
326-
Note that casting away a const qualifier and then mutating is undefined
327-
behavior, too, even when the referenced data is mutable. This is so that
328-
compilers and programmers can make assumptions based on const alone. For
325+
$(UNDEFINED_BEHAVIOR
326+
casting away a `const` qualifier and then mutating it,
327+
even when the referenced data is mutable. This is so that
328+
compilers and programmers can make assumptions based on `const` alone. For
329329
example, here it may be assumed that $(D f) does not alter $(D x):
330330
)
331331

spec/declaration.dd

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,8 +590,9 @@ $(GNAME VoidInitializer):
590590
$(P Normally, variables are initialized either with an explicit
591591
$(GLINK Initializer) or are set to the default value for the
592592
type of the variable. If the $(I Initializer) is $(D void),
593-
however, the variable is not initialized. If its value is
594-
used before it is set, undefined program behavior will result.
593+
however, the variable is not initialized.
594+
Void initializers for objects that contain indirections is not
595+
allowed in @safe code.
595596
)
596597

597598
$(IMPLEMENTATION_DEFINED If a void initialized variable's value is

spec/function.dd

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ $(H3 $(LNAME2 pure-special-cases, Special Cases))
456456

457457
$(UNDEFINED_BEHAVIOR occurs if these flags are not restored to their
458458
initial state upon function exit. It is the programmer's responsibility
459-
to ensure this.)
459+
to ensure this. Setting these flags is not allowed in `@safe` code.)
460460

461461
$(P A pure function can perform impure operations in statements that are in a
462462
$(GLINK2 version, ConditionalStatement)
@@ -2969,6 +2969,10 @@ void test()
29692969
is not allowed in @safe functions.
29702970
)
29712971

2972+
$(UNDEFINED_BEHAVIOR Calling a function pointer that was set to point to
2973+
a function that requires a context pointer.
2974+
)
2975+
29722976
---
29732977
struct S
29742978
{

spec/lex.dd

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,7 @@ $(GNAME TokenStringToken):
403403

404404
$(P String literals are read only.)
405405

406-
$(UNDEFINED_BEHAVIOR Writes to string literals
407-
cannot always be detected, but cause undefined behavior.)
406+
$(UNDEFINED_BEHAVIOR writing to a string literal. This is not allowed in `@safe` code.)
408407

409408
$(H3 $(LNAME2 wysiwyg, Wysiwyg Strings))
410409

spec/statement.dd

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,8 +1322,7 @@ $(H3 $(LNAME2 no-implicit-fallthrough, No Implicit Fall-Through))
13221322
$(P A $(GLINK ScopeStatementList) must either be empty, or be ended with
13231323
a $(GLINK ContinueStatement), $(GLINK BreakStatement),
13241324
$(GLINK ReturnStatement), $(GLINK GotoStatement), $(GLINK2 expression, ThrowExpression)
1325-
or `assert(0)` expression unless this is the last case. This is to
1326-
set apart with C's error-prone implicit fall-through behavior.)
1325+
or `assert(0)` expression unless this is the last case.)
13271326

13281327
--------------
13291328
switch (i)

0 commit comments

Comments
 (0)