diff --git a/SWIG/Source/CParse/parser.y b/SWIG/Source/CParse/parser.y index 485580dc1..5877acd5e 100644 --- a/SWIG/Source/CParse/parser.y +++ b/SWIG/Source/CParse/parser.y @@ -2679,6 +2679,8 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va for (s = First(bases); s.item; s = Next(s)) { Symtab *st = Getattr(s.item,k_symtab); if (st) { + Setfile(st,Getfile(s.item)); + Setline(st,Getline(s.item)); Swig_symbol_inherit(st); } } @@ -3183,6 +3185,8 @@ cpp_class_decl : for (s = First(bases); s.item; s = Next(s)) { Symtab *st = Getattr(s.item,k_symtab); if (st) { + Setfile(st,Getfile(s.item)); + Setline(st,Getline(s.item)); Swig_symbol_inherit(st); } } @@ -3784,10 +3788,14 @@ cpp_using_decl : USING idcolon SEMI { } if (n) { if (Strcmp(nodeType(n),"namespace") == 0) { + Symtab *current = Swig_symbol_current(); + Symtab *symtab = Getattr(n,k_symtab); $$ = new_node("using"); Setattr($$,"node",n); Setattr($$,k_namespace, $3); - Swig_symbol_inherit(Getattr(n,k_symtab)); + if (current != symtab) { + Swig_symbol_inherit(symtab); + } } else { Swig_error(cparse_file, cparse_line, "'%s' is not a namespace.\n", $3); $$ = 0; diff --git a/SWIG/Source/Include/swigwarn.h b/SWIG/Source/Include/swigwarn.h index 2a1ebdc59..89dd941f3 100644 --- a/SWIG/Source/Include/swigwarn.h +++ b/SWIG/Source/Include/swigwarn.h @@ -79,6 +79,7 @@ #define WARN_PARSE_EXPLICIT_TEMPLATE 320 #define WARN_PARSE_BUILTIN_NAME 321 #define WARN_PARSE_REDUNDANT 322 +#define WARN_PARSE_REC_INHERITANCE 323 #define WARN_IGNORE_OPERATOR_NEW 350 /* new */ #define WARN_IGNORE_OPERATOR_DELETE 351 /* delete */ diff --git a/SWIG/Source/Modules/typepass.cxx b/SWIG/Source/Modules/typepass.cxx index 41b2e952d..dee5ee8fd 100644 --- a/SWIG/Source/Modules/typepass.cxx +++ b/SWIG/Source/Modules/typepass.cxx @@ -236,10 +236,16 @@ class TypePass : private Dispatcher { SwigType_inherit_scope(scopes); } /* Set up inheritance in the symbol table */ - Symtab *s = Swig_symbol_current(); Symtab *st = Getattr(cls,"symtab"); + Symtab *bst = Getattr(bclass,"symtab"); + if (st == bst) { + Swig_warning(WARN_PARSE_REC_INHERITANCE, Getfile(cls), Getline(cls), + "Recursive scope inheritance of '%s'.\n", HashGetAttr(cls,k_name)); + continue; + } + Symtab *s = Swig_symbol_current(); Swig_symbol_setscope(st); - Swig_symbol_inherit(Getattr(bclass,"symtab")); + Swig_symbol_inherit(bst); Swig_symbol_setscope(s); /* Recursively hit base classes */ diff --git a/SWIG/Source/Swig/symbol.c b/SWIG/Source/Swig/symbol.c index 05acccc34..df8862200 100644 --- a/SWIG/Source/Swig/symbol.c +++ b/SWIG/Source/Swig/symbol.c @@ -412,6 +412,12 @@ void Swig_symbol_inherit(Symtab *s) { Setattr(current_symtab,k_inherit, inherit); Delete(inherit); } + + if (s == current_symtab) { + Swig_warning(WARN_PARSE_REC_INHERITANCE, Getfile(s), Getline(s), + "Recursive scope inheritance of '%s'.\n", HashGetAttr(s,k_name)); + return; + } assert(s != current_symtab); ilen = Len(inherit); for (i = 0; i < ilen; i++) {