Incorrectly Identifying a Value stored is never read

  • Enterprise Edition
  • Version 9.6 (build 59041)
	POSITION   pos;
	CSelectedDays* pt;
	pos = m_pCalendarIntervalDays->GetHeadPosition();
	while (pos != NULL)
		BOOL timeCodeMatches = FALSE;
		pt = (CSelectedDays*)m_pCalendarIntervalDays->GetNext(pos);
Value stored to 'pt' is never read <<<<<<<<<<<SONAR QUBE ISSUE
		for each (CBulkOverrideDays * bulkOverrideDay in pt->m_BulkOverrideDays)
			timeCodeMatches = pt->HoursAppliesToAllTimeCodes();

This is one example where SonarQube thinks the variable pt is not being used, yet it is used in the for loop


Welcome to the community!

What language is this?


Visual C++ (Visual Studio 2022)

1 Like

Hello @Dave_Adams,

for each is a Microsoft extension (C++/CLI) that we do not support.

The following standard versions are supported in SonarQube 9.6:

Supported Language Standards

  • C89, C99, C11, C18, C++03, C++11, C++14, C++17, and C++20 standards
  • GNU extensions

I believe there should be a parse error around that line looking like expected ‘(’ after ‘for’.

Once fixed, the issue you mentioned should be gone too.

Quoting Microsoft documentation on for each:

This non-standard keyword is available in both C++/CLI and native C++ projects. However, its use isn’t recommended. Consider using a standard Range-based for Statement (C++) instead.

I hope this helps.

1 Like