[cpp:S978] Falsely triggered when using local alias/typedef

I’m getting what I think is a false positive for this rule:

Reserved identifiers and functions in the C stand#ard library should not be defined or declared

The following code triggers it – I’m using local aliases to make the code more readable:

#include <cmath>

struct Coord {  double azimuth; double elevation; };

double myFunction(const Coord& a, const Coord& b)
    using std::sin;  // this triggers cpp:S978
    using std::cos;  // this triggers cpp:S978

    return (sin(a.elevation) * sin(b.elevation) + 
            cos(a.elevation) * cos(b.elevation) * cos(a.azimuth - b.azimuth));

I think for local (within function) aliases like this, this rule should not be applied.

A workaround would be to add a using std::namespace within this function, but I don’t see the harm in using function aliases instead.

I’m on Sonarqube Developer Edition - Version 9.9 (build 65466)

Hi @Sidelobe,

Thanks for raising this issue.

I agree with your assessment and I’ve created [CPP-4429] - Jira to track this bug.


1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.