Opened 3 years ago

#243 new enhancement

Add warning for thread casts in constructors

Reported by: Thierry Delisle Owned by:
Priority: minor Component: cfa-cc
Version: 1.0 Keywords: thread cast
Cc:

Description

When not using the thread keyword, thread casts are unsafe in constructors.

The following code for example:

struct SomeThread {
	$thread self;
	// ...
};
// ...
void ?{}( SomeThread & this, /*...*/ ) {
	((thread&)this){/*...*/};
}

leads to undefined behaviour because the constructor of 'self' will be called twice.
We should add a warning or error for this. An easy fix would be to warn against thread casts in the constructor, but that could lead to many false positives. A better but harder approach would be to detect the case where this breaks, but that requires some amount of tracing through resolved code.

Change History (0)

Note: See TracTickets for help on using tickets.