Closed llvmbot closed 9 years ago
This doesn't reproduce on trunk for me, I believe r234675 fix this: Author: Reid Kleckner reid@kleckner.net CommitDate: Sat Apr 11 01:25:36 2015 +0000
Only notify consumers about static data members of class templates once
I'll take a look.
We presumably don't use a guard variable for dynamic initialization of a non-externally-visible static data member, but somehow we manage to emit the initialization multiple times.
David, can I tempt you with this?
assigned to @majnemer
Extended Description
I wrote a class template that increments a static counter integer based on the template parameters. Clang produces differing output based on whether or not the template parameters are global or function local types. The output with function local types seems wrong. GCC and MSVC do not produce this behavior.
The code was compiled with: clang++ -std=c++11 -O2 -Wall -pedantic -pthread main.cpp && ./a.out
// == Code == //
include
include
include
include
include
include
using uint = unsigned int;
template<typename SK,typename T> struct Component { static uint const index; };
template
class ComponentCount
{
template<typename CSK,typename CT>
friend struct Component;
private: template
static uint next() {
return ComponentCount::get_counter();
}
};
template<typename SK,typename T> uint const Component<SK,T>::index(ComponentCount::template next());
// global scope struct X {}; struct Y {};
int main() { // function scope struct Z{};
}
// == Expected output == //
Each of the three cout statements should print out: 0, 1, 1, 2, 0, 0
When compiled with clang, the last statement (using the function local type 'Z') prints out: 5, 2, 2, 3, 5, 5
A reference example that can be run in-browser can be found here (link may not be permanent)
http://coliru.stacked-crooked.com/a/7fcb989ae6eab476