In many cases the default constructor of a class contains initializer of data
members, which allows concise code. The class may be instantiated as
global or automatic variables in device code, which is totally legal. However
when such a class is instantiated as a shared variable in device code, clang
will emit an error saying shared variables cannot be initialized.
Usually, users would like to just add explicit initialization for the shared variable,
instead of remove the initializer of data members from the default constructor,
since that would requires adding explicit initialization to all instances of the class,
even as global or automatic variables.
This requires the diagnostic of initialization of shared variable to be a warning,
instead of an error.
nvcc emits an warning for such situation, e.g.
$ cat a.cu struct A { int a; __device__ A():a(0){} }; __global__ void foo() { __shared__ A a; } $nvcc -c a.cu a.cu(10): warning: __shared__ memory variable with non-empty constructor or destructor (potential race between threads)
This patch turns the diagnostic of initialization of shared varibles into a warning.
By default it is still treated as error, therefore no behavior change of clang. However,
user can turn it into a warning by -Wno-error=cuda-shared-init.