Hi,
I tried to compile my simple test:
#define __declspec
#include <vector>
int main() {
std::vector<int> v;
return 0;
}
and for the first time the include of <vector> work (ie no parsing error), good. (note that I am using clang on windows with the mingw 3.4.5 headers and that the define __declspec is needed. perhaps it should be added to the predefined macro? as clang support the dllimport attribute)
now, the instanciation of the vector assert:
Assertion failed: false && "Unable to find declaration for the current instantiation", file ..\..\..\..\..\tools\clang\lib\Sema\SemaTemplateInstantiateDecl.cpp, line 1411
(I suppose this is know, but if not, I attached the zipped preprocessed output (clang-cc -E))
anyways, great work!
regards,
Cédric
test.zip (23 KB)
Hi,
I tried to compile my simple test:
#define __declspec
#include
int main() {
std::vector v;
return 0;
}
and for the first time the include of work (ie no parsing error), good.
Yes, we’re able to parse a bunch of libstdc++ headers now without spurious errors, but (as you’ve seen) we’re a long way from being able to handle C++ programs.
(note that I am using clang on windows with the mingw 3.4.5 headers and that the define __declspec is needed. perhaps it should be added to the predefined macro? as clang support the dllimport attribute)
We have some support for parsing __declspec already, but I’m sure that we’re missing it when parsing some C++ constructs. What kinds of problems are you seeing with __declspec?
now, the instanciation of the vector assert:
Assertion failed: false && “Unable to find declaration for the current instantiation”, file …\tools\clang\lib\Sema\SemaTemplateInstantiateDecl.cpp, line 1411
FWIW, this is coming from an attempt to instantiate a default argument expression in a template (that refers to a typedef), e.g.,
template
struct X1 {
typedef T value_type;
X1(const value_type& value = value_type());
};
void test_X1() {
X1 x1;
}
I should have a fix soon.
(note that I am using clang on windows with the mingw 3.4.5 headers and that the define __declspec is needed. perhaps it should be added to the predefined macro? as clang support the dllimport attribute)
We have some support for parsing __declspec already, but I'm sure that we're missing it when parsing some C++ constructs. What kinds of problems are you seeing with __declspec?
It is mingw specific and not a problem on declspec. In _mingw.h, there is:
#ifndef __GNUC__
# ifndef __MINGW_IMPORT
# define __MINGW_IMPORT __declspec(dllimport)
# endif
# ifndef _CRTIMP
# define _CRTIMP __declspec(dllimport)
# endif
# define __DECLSPEC_SUPPORTED
# define __attribute__(x) /* nothing */
#else /* __GNUC__ */
# ifdef __declspec
# ifndef __MINGW_IMPORT
/* Note the extern. This is needed to work around GCC's
limitations in handling dllimport attribute. */
# define __MINGW_IMPORT extern __attribute__ ((__dllimport__))
# endif
# ifndef _CRTIMP
# ifdef __USE_CRTIMP
# define _CRTIMP __attribute__ ((dllimport))
# else
# define _CRTIMP
# endif
# endif
# define __DECLSPEC_SUPPORTED
# else /* __declspec */
# undef __DECLSPEC_SUPPORTED
# undef __MINGW_IMPORT
# ifndef _CRTIMP
# define _CRTIMP
# endif
# endif /* __declspec */
and if __MINGW_IMPORT is not defined, there is problems latter in the compilation (in time.h for exemple).
So when you have __GNUC__ defined, you have to have __declspec defined, else it does not work. Anyway putting a define __declspec allowed me to parse this, even if it is a big hack)
(in fact if __MSVCRT__ can be undefined, __MINGW_IMPORT should not be used...)
now, the instanciation of the vector assert:
Assertion failed: false && "Unable to find declaration for the current instantiation", file ..\..\..\..\..\tools\clang\lib\Sema\SemaTemplateInstantiateDecl.cpp, line 1411
FWIW, this is coming from an attempt to instantiate a default argument expression in a template (that refers to a typedef), e.g.,
I see, thanks for the explanation. I must say I am eager to have good c++ semantic analyse working to be able to use clang for static analysis and inteligent refactoring, but I know the task is daunting so I am waiting. Sadly I don't have enough times to contribute (need to finish my phd first). just following the project is already quite time consuming 
regards,
Cédric
(note that I am using clang on windows with the mingw 3.4.5 headers and that the define __declspec is needed. perhaps it should be added to the predefined macro? as clang support the dllimport attribute)
We have some support for parsing __declspec already, but I’m sure that we’re missing it when parsing some C++ constructs. What kinds of problems are you seeing with __declspec?
It is mingw specific and not a problem on declspec. In _mingw.h, there is:
#ifndef GNUC
ifndef __MINGW_IMPORT
define __MINGW_IMPORT __declspec(dllimport)
endif
ifndef _CRTIMP
define _CRTIMP __declspec(dllimport)
endif
define __DECLSPEC_SUPPORTED
define attribute(x) /* nothing */
#else /* GNUC */
ifdef __declspec
ifndef __MINGW_IMPORT
/* Note the extern. This is needed to work around GCC’s
limitations in handling dllimport attribute. */
define __MINGW_IMPORT extern attribute ((dllimport))
endif
ifndef _CRTIMP
ifdef __USE_CRTIMP
define _CRTIMP attribute ((dllimport))
else
define _CRTIMP
endif
endif
define __DECLSPEC_SUPPORTED
else /* __declspec */
undef __DECLSPEC_SUPPORTED
undef __MINGW_IMPORT
ifndef _CRTIMP
define _CRTIMP
endif
endif /* __declspec */
and if __MINGW_IMPORT is not defined, there is problems latter in the compilation (in time.h for exemple).
So when you have GNUC defined, you have to have __declspec defined, else it does not work. Anyway putting a define __declspec allowed me to parse this, even if it is a big hack)
(in fact if MSVCRT can be undefined, __MINGW_IMPORT should not be used…)
Okay, so we need to be defining __declspec on mingw targets. That involves creating a new target for MinGW32/64 (in lib/Basic/Targets.cpp) that adds these defines into its getTargetDefines() function. The actual spelling of the predefined __declspec (and any other mingw-specific macros) will be shown in the output of
touch foo.cpp
g++ -dM -E foo.cpp
now, the instanciation of the vector assert:
Assertion failed: false && “Unable to find declaration for the current instantiation”, file …\tools\clang\lib\Sema\SemaTemplateInstantiateDecl.cpp, line 1411
FWIW, this is coming from an attempt to instantiate a default argument expression in a template (that refers to a typedef), e.g.,
I see, thanks for the explanation. I must say I am eager to have good c++ semantic analyse working to be able to use clang for static analysis and inteligent refactoring, but I know the task is daunting so I am waiting.
We’re inching closer 