[LLVMbugs] [Bug 10001] New: Clang fails to instantiate an initializer required to complete a type
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Tue May 24 01:29:49 PDT 2011
http://llvm.org/bugs/show_bug.cgi?id=10001
Summary: Clang fails to instantiate an initializer required to
complete a type
Product: clang
Version: unspecified
Platform: PC
OS/Version: All
Status: NEW
Severity: normal
Priority: P
Component: C++
AssignedTo: unassignedclangbugs at nondot.org
ReportedBy: chandlerc at gmail.com
CC: llvmbugs at cs.uiuc.edu, dgregor at apple.com
Clang isn't properly instantiating templates when it is required to do so to
complete some types:
% cat x.cc
template <typename T> struct S {
static const int arr[];
static const int x;
static int f();
};
template <typename T> const int S<T>::arr[] = { 1, 2, 3 };
template <typename T> const int S<T>::x = sizeof(arr) / sizeof(arr[0]);
template <typename T> int S<T>::f() { return x; }
int x = S<int>::f();
% ./bin/clang -fsyntax-only x.cc
x.cc:8:43: error: invalid application of 'sizeof' to an incomplete type 'const
int []'
template <typename T> const int S<T>::x = sizeof(arr) / sizeof(arr[0]);
^~~~~~~~~~~
x.cc:9:46: note: in instantiation of static data member 'S<int>::x' requested
here
template <typename T> int S<T>::f() { return x; }
^
x.cc:11:17: note: in instantiation of member function 'S<int>::f' requested
here
int x = S<int>::f();
^
1 error generated.
It looks like this would work were the types class types, but because they're
non-class-types, we assume their completeness doesn't require instantiation.
Doh. This has nothing to do with sizeof(), this is broken in innumerable
contexts in Clang, the fundamental API for causing a type to become complete
fails to consider this scenario as far as I can tell.
--
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
More information about the llvm-bugs
mailing list