diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java index 7a739d0edb5..b46019c27a9 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java @@ -2164,5 +2164,65 @@ public class CompleteParseASTTest extends CompleteParseBaseTest parse( writer.toString() ); assertFalse( callback.getProblems().hasNext() ); } + + + public void testBug72692A() throws Exception + { + Writer writer = new StringWriter(); + writer.write( "extern double pow(double, double);\n"); + writer.write( "extern double pow2(double, double){}\n"); + writer.write( "namespace DS {\n"); + writer.write( "using ::pow;\n"); + writer.write( "using ::pow2;\n"); + writer.write( "}\n"); + writer.write( "using DS::pow;\n"); + writer.write( "using DS::pow2;\n"); + parse( writer.toString() ); + } + + public void testBug72692B() throws Exception + { + Writer writer = new StringWriter(); + writer.write( "extern double pow(double, double);\n"); + writer.write( "namespace DS {\n"); + writer.write( "using ::pow;\n"); + writer.write( "inline float pow(float __x, float __y)\n" ); + writer.write( "{ return ::pow(static_cast(__x), static_cast(__y)); }\n" ); + writer.write( "}\n"); + writer.write( "using namespace DS;\n"); + writer.write( "float foo() { double d1 = 3.0, d2 = 4.0; return pow(d1, d2); }"); + parse( writer.toString() ); + } + + public void testBug72692C() throws Exception + { + Writer writer = new StringWriter(); + writer.write( "extern double pow(double, double){}\n"); + writer.write( "namespace DS {\n"); + writer.write( "using ::pow;\n"); + writer.write( "}\n"); + writer.write( "using DS::pow;\n"); + parse( writer.toString() ); + } + + + public void testBug74575A() throws Exception + { + Writer writer = new StringWriter(); + writer.write( "double pow(double, double);\n"); + writer.write( "float pow(float __x, float __y)\n" ); + writer.write( "{ return 0; }\n"); + Iterator i = parse( writer.toString() ).getDeclarations(); + IASTFunction doublePow = (IASTFunction) i.next(); + IASTFunction floatPow = (IASTFunction) i.next(); + assertFalse( i.hasNext() ); + assertEquals( floatPow.getName(), "pow" ); + assertEquals( doublePow.getName(), "pow"); + assertEquals( ((IASTSimpleTypeSpecifier)doublePow.getReturnType().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.DOUBLE ); + assertEquals( ((IASTSimpleTypeSpecifier)floatPow.getReturnType().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.FLOAT ); + assertFalse( doublePow.hasFunctionBody() ); + assertTrue( floatPow.hasFunctionBody() ); + } + } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java index 256057f31bc..cd671df3690 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java @@ -1172,7 +1172,7 @@ public class ParserSymbolTableTest extends TestCase { assertEquals( using.getReferencedSymbols().get(0), f1 ); - IParameterizedSymbol usingF = (IParameterizedSymbol)using.getDeclaredSymbols().get(0); + IParameterizedSymbol usingF = (IParameterizedSymbol)using.getReferencedSymbols().get(0); look = compUnit.lookup("A".toCharArray()); //$NON-NLS-1$ assertEquals( look, A ); @@ -1210,13 +1210,10 @@ public class ParserSymbolTableTest extends TestCase { assertTrue( list.contains( f1 ) ); assertTrue( list.contains( f2 ) ); assertEquals( list.size(), 2 ); - - int index = list.indexOf( f2 ); - list = using.getDeclaredSymbols(); look = bar.unqualifiedFunctionLookup( "f".toCharArray(), paramList ); //$NON-NLS-1$ assertTrue( look != null ); - assertEquals( look, list.get( index ) ); + assertEquals( look, f2); assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTFunction.java index b2d37474c54..bdb9863f5dd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTFunction.java @@ -136,7 +136,7 @@ public class ASTFunction extends ASTScope implements IASTFunction */ public void setHasFunctionBody(boolean b) { - hasFunctionBody = true; + hasFunctionBody = b; } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTFunction#hasFunctionBody() diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java index 3b166f51829..bb527b21c51 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java @@ -1969,8 +1969,10 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto type = ITypeInfo.t_bool; else if( kind == IASTSimpleTypeSpecifier.Type.CHAR ) type = ITypeInfo.t_char; - else if( kind == IASTSimpleTypeSpecifier.Type.DOUBLE ||kind == IASTSimpleTypeSpecifier.Type.FLOAT ) + else if( kind == IASTSimpleTypeSpecifier.Type.DOUBLE ) type = ITypeInfo.t_double; + else if( kind == IASTSimpleTypeSpecifier.Type.FLOAT ) + type = ITypeInfo.t_float; else if( kind == IASTSimpleTypeSpecifier.Type.INT ) type = ITypeInfo.t_int; else if( kind == IASTSimpleTypeSpecifier.Type.VOID ) @@ -2187,8 +2189,12 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto symbol = functionDeclaration; } - ASTFunction function = new ASTFunction( symbol, nameEndOffset, parameters, returnType, exception, startOffset, startLine, nameOffset, nameLine, ownerTemplate, references, previouslyDeclared, hasFunctionTryBlock, isFriend, filename ); - attachSymbolExtension(symbol, function, isFunctionDefinition); + ASTFunction function = new ASTFunction( symbol, nameEndOffset, parameters, returnType, exception, startOffset, startLine, nameOffset, nameLine, ownerTemplate, references, previouslyDeclared, hasFunctionTryBlock, isFriend, filename ); + + attachSymbolExtension(symbol, function, isFunctionDefinition); + + function.setHasFunctionBody(isFunctionDefinition); + return function; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ContainerSymbol.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ContainerSymbol.java index ca996190617..56b0a5c3d37 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ContainerSymbol.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ContainerSymbol.java @@ -400,6 +400,10 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol { addedUsingToContained = true; } clone = (ISymbol) symbol.clone(); //7.3.3-9 + + clone.setForwardSymbol(symbol); + clone.setIsForwardDeclaration(true); + addSymbol( clone ); } else { throw new ParserSymbolTableException( ParserSymbolTableException.r_InvalidUsing ); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java index 03be0a3bb46..fbcf091abff 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java @@ -487,7 +487,7 @@ public class ParserSymbolTable { if( foundSymbol.isType( ITypeInfo.t_function ) ){ if( foundSymbol.isForwardDeclaration() && foundSymbol.getForwardSymbol() != null && - foundSymbol.getForwardSymbol().getContainingSymbol() == foundSymbol.getContainingSymbol() ) + !foundSymbol.isTemplateInstance() && foundSymbol.getForwardSymbol().getContainingSymbol() != null) { foundSymbol = foundSymbol.getForwardSymbol(); } @@ -821,6 +821,12 @@ public class ParserSymbolTable { return true; newType = newSymbol.getType(); } + + // handle reverse-forward 'using' decls + if( newSymbol.isForwardDeclaration() ){ + if( newSymbol.getForwardSymbol() == origSymbol ) + return true; + } //handle forward decls if( origSymbol.isForwardDeclaration() ){