In general CUDA does not allow dynamic initialization of
global device-side variables except for records with empty constructors as described in section E.2.3.1 of
CUDA 7.5 Programming guide:
device, constant and shared variables defined in namespace scope,
that are of class type, cannot have a non-empty constructor or a non-empty destructor.
A constructor for a class type is considered empty at a point in the translation unit,
if it is either a trivial constructor or it satisfies all of the following conditions:
- The constructor function has been defined.
- The constructor function has no parameters, the initializer list is empty and the function body is an empty compound statement.
- Its class has no virtual functions and no virtual base classes.
- The default constructors of all base classes of its class can be considered empty.
- For all the nonstatic data members of its class that are of class type (or array thereof), the default constructors can be considered empty.
Clang is already enforcing no-initializers for shared variables, but currently allows dynamic initialization for device and constant variables.
This patch applies initializer checks for all device-side variables.
Empty constructors are accepted, but no code is generated for them.
Nit, but, since we're all language nerds here, suggest adding an Oxford comma.