Skip to content

Spurious warnings about duplicated loop indices #584

@jbarczak

Description

@jbarczak

The example below emits spurious redefinition warnings about the loop iterator. It appears that permissive scoping rules are in use. This may be intentional, to match old compiler behavior, but if so, it might be better to hide it behind a compatibility switch, since C++ has moved past this.

uint g_count1;
uint g_count2;
Buffer<float4> Things;

float4 main() : SV_Target
{
	float4 data=0;
	for( uint i=0; i<g_count1; i++ )
	{
		data += Things[i];
	}

	for( uint i=0; i<g_count2; i++ )
	{
		data += Things[g_count1+i];
	}

	return data;
}
C:\scratch\hlsl.bin\Debug\bin>dxc -T ps_6_0 test.txt
test.txt:14:12: warning: redefinition of 'i' shadows declaration in the outer scope; most recent declaration will be used
        for( uint i=0; i<g_count2; i++ )
                  ^
test.txt:9:12: note: previous definition is here
        for( uint i=0; i<g_count1; i++ )
                  ^

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions