For Programmers: Free Programming Magazines  


Home > Archive > VC STL > March 2006 > VC++ 8 : compiler bug ? (Is /GL a safe feature ?)









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author VC++ 8 : compiler bug ? (Is /GL a safe feature ?)
Aurelien Regat-Barrel

2006-03-16, 7:01 pm

Hi,
2 days ago, we encountered a crash in our program because we linked a
non /GL exe with a /GL static lib.
Today, I found a new bug, due to /GL again. Here is an example showing
the problem:

test.cpp:
========

#define _SECURE_SCL 0 // <-- modifies the behaviour of std::vector
#include <vector>
#include <algorithm>

void test()
{
std::vector<int> v( 150, 10 );
std::vector<int>::iterator max_i =
std::max_element( v.begin(), v.end() );
int max = *max_i; // <------- CRASH with /GL
}


main.cpp
========

#include <vector> // <-- without _SECURE_SCL defined...

// explicit instanciation
template class std::vector<int, std::allocator< int > >;

void test();

int main()
{
test();
return 0;
}

In release, without /GL, this code works well. With /GL, it crashes.
Is it a normal behaviour ?

Thanks.

--
Aurélien Regat-Barrel
Bo Persson

2006-03-16, 7:01 pm


"Aurelien Regat-Barrel" <nospam.aregatba@yahoo.fr.invalid> skrev i
meddelandet news:OnQztdRSGHA.1780@TK2MSFTNGP12.phx.gbl...
> Hi,
> 2 days ago, we encountered a crash in our program because we linked
> a non /GL exe with a /GL static lib.
> Today, I found a new bug, due to /GL again. Here is an example
> showing the problem:
>
> test.cpp:
> ========
>
> #define _SECURE_SCL 0 // <-- modifies the behaviour of
> std::vector
> #include <vector>


> std::vector<int> v( 150, 10 );


> main.cpp
> ========
>
> #include <vector> // <-- without _SECURE_SCL defined...
>
> // explicit instanciation
> template class std::vector<int, std::allocator< int > >;


You can't do this, as it creates two different versions of
std::vector<int>.

The C++ standard formulates the One Definition Rule, stating that all
defintions of a type must be the same. In your case they are not, as
they are compiled with different options.

The /GL isn't causing the problem, it just happens to make it visible.


Bo Persson


Aurelien Regat-Barrel

2006-03-20, 7:58 am

Bo Persson wrote :
> You can't do this, as it creates two different versions of
> std::vector<int>.
>
> The C++ standard formulates the One Definition Rule, stating that all
> defintions of a type must be the same. In your case they are not, as
> they are compiled with different options.
>
> The /GL isn't causing the problem, it just happens to make it visible.


Ok. Thank you.

--
Aurélien Regat-Barrel
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com