#1238 Compiler error with C++ using declarations

open
nobody
5
2012-12-21
2012-04-21
No

I can successfully wrap the following C++ file, called test_vector.hpp:

#include <string>
#include <vector>
using std::string;
using std::vector;
struct S
{
string a;
vector<int> b;
};

using the following interface file:

%module test_vector
%{
#include "test_vector.hpp"
%} %include "std_vector.i"
%include "std_string.i"
%include "test_vector.hpp"

and the following commands:

swig -php -c++ test_vector.ig++
`php-config5 --includes` -fpic -c test_vector_wrap.cpp

However, if I add an enclosing namespace, as follows:

#include <string>
#include <vector>
namespace N
{
using std::string;
using std::vector;
struct S
{
string a;
vector<int> b;
};
}

and try to compile with the same interface file and commands, the second command
gives the following errors:

test_vector_wrap.cpp: In function ‘void _wrap_S_b_set(int, zval*, zval**, zval*, int)’:
test_vector_wrap.cpp:1201:3: error: ‘vector’ was not declared in this scope
test_vector_wrap.cpp:1201:3: note: suggested alternatives:/usr/include/c++/4.6/bits/stl_vector.h:180:11:
note: ‘std::vector’/usr/include/c++/4.6/bits/stl_vector.h:180:11:
note: ‘std::vector’
test_vector_wrap.cpp:1201:11: error: expected primary-expression before ‘int’
test_vector_wrap.cpp:1201:11: error: expected ‘;’ before ‘int’
test_vector_wrap.cpp:1202:11: error: expected primary-expression before ‘int’
test_vector_wrap.cpp:1202:11: error: expected ‘;’ before ‘int’
test_vector_wrap.cpp:1217:8: error: ‘tmp2’ was not declared in this scope
test_vector_wrap.cpp:1220:5: error: ‘arg2’ was not declared in this scope
test_vector_wrap.cpp:1220:13: error: ‘tmp2’ was not declared in this scope
test_vector_wrap.cpp:1222:25: error: ‘arg2’ was not declared in this scope
test_vector_wrap.cpp: In function ‘void _wrap_S_b_get(int, zval*, zval**, zval*, int)’:
test_vector_wrap.cpp:1233:3: error: ‘vector’ was not declared in this scope
test_vector_wrap.cpp:1233:3: note: suggested alternatives:
/usr/include/c++/4.6/bits/stl_vector.h:180:11: note: ‘std::vector’
/usr/include/c++/4.6/bits/stl_vector.h:180:11: note: ‘std::vector’
test_vector_wrap.cpp:1233:11: error: expected primary-expression before ‘int’
test_vector_wrap.cpp:1233:11: error: expected ‘;’ before ‘int’
test_vector_wrap.cpp:1246:3: error: ‘result’ was not declared in this scope
test_vector_wrap.cpp:1248:13: error: expected primary-expression before ‘int’
test_vector_wrap.cpp:1248:13: error: expected ‘;’ before ‘int’
test_vector_wrap.cpp:1249:5: error: ‘resultobj’ was not declared in this scope

Interestingly, I do not get any errors about string, even though my code treatsstring and vector exactly the same.

Related

Bugs: #1310

Discussion

  • William Fulton

    William Fulton - 2012-04-28

    There are a few simiilar bugs wrt using 'using'. Workaround is to avoid it for now.

     
  • William Fulton

    William Fulton - 2012-06-30

    Looks related to #3497393

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks