From: Mikko Rasa Date: Mon, 8 Mar 2021 00:49:40 +0000 (+0200) Subject: Improve reporting of function name conflicts X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=01c59fefa142fe7812db32e703bbe52a0c14a2bb;p=libs%2Fgl.git Improve reporting of function name conflicts Prototype declarations were not being recorded, and definitions were causing multiple definition errors to be reported in double. --- diff --git a/source/glsl/validate.cpp b/source/glsl/validate.cpp index 2f02400e..fcccb526 100644 --- a/source/glsl/validate.cpp +++ b/source/glsl/validate.cpp @@ -156,11 +156,16 @@ void DeclarationValidator::visit(InterfaceBlock &iface) void DeclarationValidator::visit(FunctionDeclaration &func) { if(Statement *previous = find_definition(func.name)) - if(!dynamic_cast(previous)) + { + FunctionDeclaration *prev_func = dynamic_cast(previous); + if(prev_func && prev_func->definition==&func) + declarations[current_block][func.name] = &func; + else multiple_definition(format("'%s'", func.name), func, *previous); + } + else + record_definition(func.name, func); - if(func.definition==&func) - check_definition(func.name, func); TraversingVisitor::visit(func); } diff --git a/tests/glsl/identifier_conflict.glsl b/tests/glsl/identifier_conflict.glsl index 3e10089b..b0cd34a6 100644 --- a/tests/glsl/identifier_conflict.glsl +++ b/tests/glsl/identifier_conflict.glsl @@ -4,6 +4,7 @@ out VertexOut { vec2 texcoord; } vs_out; +vec3 normal(); vec3 normal; out VertexOut2 { @@ -22,10 +23,12 @@ vec2 texcoord() } /* Expected error: -:11: Multiple definition of 'normal' +:8: Multiple definition of 'normal' :7: Previous definition is here -:13: Multiple definition of 'texcoord' -:10: Previous definition is here -:19: Multiple definition of 'texcoord' -:10: Previous definition is here +:12: Multiple definition of 'normal' +:7: Previous definition is here +:14: Multiple definition of 'texcoord' +:11: Previous definition is here +:20: Multiple definition of 'texcoord' +:11: Previous definition is here */