Visual Studio 9 2008 compile error in ASTContext.cpp

I am getting the following error when compiling clang with Visual Studio 9 2008 (cmake -G “Visual Studio 9 2008”). My git checkout is at [commit cea06d26b8f3a2599bba79f7e072b7550de949a7, git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158869]. Any one else tried seeing this error?

C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\xutility(315) : error C2664: ‘bool clang::BeforeThanCompareclang::RawComment::operator ()(const clang::RawComment &,const clang::SourceRange &)’ : cannot convert parameter 1 from ‘const clang::SourceRange’ to ‘const clang::RawComment &’
Reason: cannot convert from ‘const clang::SourceRange’ to ‘const clang::RawComment’
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\algorithm(2298) : see reference to function template instantiation ‘bool std::_Debug_lt_pred<_Pr,T,_Ty>(_Pr,const _Ty1 &,const _Ty2 &,const wchar_t ,unsigned int)’ being compiled
with
[
_Pr=clang::BeforeThanCompareclang::RawComment,
T=clang::RawComment,
_Ty=clang::SourceRange,
_Ty1=clang::RawComment,
_Ty2=clang::SourceRange
]
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\algorithm(2312) : see reference to function template instantiation '_FwdIt std::_Lower_bound<const clang::RawComment
,_Ty,std::iterator_traits<_Iter>::difference_type,_Pr>(_FwdIt,_FwdIt,const _Ty &,_Pr,_Diff *)’ being compiled
with
[
_FwdIt=const clang::RawComment *,
_Ty=clang::SourceRange,
_Iter=const clang::RawComment *,
_Pr=clang::BeforeThanCompareclang::RawComment,
_Diff=std::iterator_traits<const clang::RawComment >::difference_type
]
…\tools\clang\lib\AST\ASTContext.cpp(85) : see reference to function template instantiation '_FwdIt std::lower_bound<const clang::RawComment
,clang::SourceRange,clang::BeforeThanCompareclang::RawComment>(_FwdIt,_FwdIt,const _Ty &,_Pr)’ being compiled
with
[
_FwdIt=const clang::RawComment *,
_Ty=clang::SourceRange,
_Pr=clang::BeforeThanCompareclang::RawComment
]

[Manjunath Kudlur]

I am getting the following error when compiling clang with Visual Studio 9 2008 (cmake -G "Visual Studio 9 2008").

clang is invoking lower_bound() with a heterogeneous comparison - the provided value is of a different type than the elements. VC8 and VC9 have debug checks that perform homogenous comparisons (to ensure that the input range is actually sorted), so you get a compiler error if homogeneous comparisons aren't available. Technically, this behavior was conformant according to C++03.

C++11's requirements were relaxed, permitting heterogeneous comparisons. Accordingly, we commented out lower_bound and upper_bound's debug checks (as an aside, we forgot equal_range, oops - this is on my todo list). So VC10+ will work here.

Even though you should *really* upgrade, there are a couple of workarounds for VC9. You could disable the debug checks, although if you're not careful this will explode horribly. To do this, define _HAS_ITERATOR_DEBUGGING to 0 globally (ideally, on the command line). Alternatively, if the element type and the value type have the "same ordering", then a source workaround is to have the comparator also provide the (ElementType, ElementType) comparison that the debug checks want.

Stephan T. Lavavej
Visual C++ Libraries Developer

Hi Manjunath,

I don't have VC9 to test. Does the attached patch fix the build for you?

Dmitri

fix-vc9.patch (1.11 KB)

Didn't include all files in the diff. Here's the correct one.

Dmitri

fix-vc9-v2.patch (1.77 KB)

Should be fixed in r158936.

Dmitri

I am getting the following error when compiling clang with Visual Studio 9
2008 (cmake -G “Visual Studio 9 2008”). My git checkout is at [commit
cea06d26b8f3a2599bba79f7e072b7550de949a7, git-svn-id:
https://llvm.org/svn/llvm-project/cfe/trunk@158869]. Any one else tried
seeing this error?

Should be fixed in r158936.

Sweet. Worked for me. Thanks.

Manjunath