Pragma or gradle flag for ignoring deprecated warnings

Folks,

Like many teams, we (Team #7464 - ORION) will be using the old command-based programming for the 2020 season. This is only our second season, so hopefully going to the new command-based programming won’t be too hard in the off-season.

That being said, we are using the old PIDController, which has also been deprecated.

From this discussion (Using Old Command-Based Programming), especially post 10, we should be okay for this season.

Is there a pragma directive or compiler flag that will disable the deprecated warnings? We know we are using deprecated code, but wish to ignore the “using deprecated code” warnings without ignoring other warnings.

Seeing the deprecation warnings gives you that sinking feeling that your code is not going to compile/link, and then you see “Build Successful” at the end. As a mentor, I’m afraid the students won’t look for any other warnings that aren’t related to deprecated code.

Any insights on how to ignore the deprecated code warnings?

They are deprecated because they are no longer recommended for use, won’t be as well maintained as non-deprecated equivalents, and could be removed in later years (although removal is unlikely for command-based v1 since it’s a vendordep now and is basically already separate).

With that said, try adding this if statement to your build.gradle:

model {
    components {
        frcUserProgram(NativeExecutableSpec) {
            binaries.all {
                if (!(toolChain instanceof VisualCpp))
                    cppCompiler.args << '-Wno-deprecated-declarations'
            }
        }
    }
}

Again, I strongly caution you against doing this.

1 Like

calcmogul:

Thank you for the help. You put me on the right path. However, I could not simply add that statement (starting with the model) at the end of the build.gradle file.

I had to insert the binaries.all block that you provided within the existing model block, as seen below (which may be what you originally intended, and I just didn’t understand that at first).

I understand the risks of ignoring warnings for deprecated code, and plan to put in our code source that we are using deprecated code, and how to remove the -Wno-deprecated-declarations statement from the build.gradle file, and pass this information along to our programmers. I just don’t them to miss other warnings because they know some are deprecated warnings.

Also, one other question: Our team pulls in the allwpilibc source into our Doxygen documentation, which generates a customized page similar to the official WPILib C++ documentation page (WPILibC++: Main Page). However, when I click on the “Deprecated List” over in the left-hand side of the above page (Deprecated List), all I see listed as deprecated is:

Member frc::CameraServer::SetSize (int size)
and
Member frc::Encoder::SetMaxPeriod (double maxPeriod) override

Should not all the old command-based programming be marked as deprecated (Deprecated Command)? This I would think would be helpful. I and our programmers have found the Doxygen documentation extremely helpful, and marking the deprecated code as deprecated would be helpful as well.

Again, thank you for the help. And thank you very much for being a WPILib developer!

======================================================================

model {
    components {
        frcUserProgram(NativeExecutableSpec) {
            targetPlatform wpi.platforms.roborio
            if (includeDesktopSupport) {
                targetPlatform wpi.platforms.desktop
            }

            sources.cpp {
                source {
                    srcDir 'src/main/cpp'
                    include '**/*.cpp', '**/*.cc'
                }
                exportedHeaders {
                    srcDir 'src/main/include'
                    if (includeSrcInIncludeRoot) {
                        srcDir 'src/main/cpp'
                    }
                }
            }

            // Defining my dependencies. In this case, WPILib (+ friends), and vendor libraries.
            wpi.deps.wpilib(it)
            wpi.deps.vendor.cpp(it)

            // From Chief Delphi contributor calcmogul, on post
	    // https://www.chiefdelphi.com/t/pragma-or-gradle-flag-for-ignoring-deprecated-warnings/375815/2
            binaries.all {
                if (!(toolChain instanceof VisualCpp)) {
                    cppCompiler.args << '-Wno-deprecated-declarations'
		}
	    }
	    // end "From Chief Delphi contributor calcmogul, on post..."
        }
    }
    testSuites {
        frcUserProgramTest(GoogleTestTestSuiteSpec) {
            testing $.components.frcUserProgram

            sources.cpp {
                source {
                    srcDir 'src/test/cpp'
                    include '**/*.cpp'
                }
            }

            wpi.deps.wpilib(it)
            wpi.deps.googleTest(it)
            wpi.deps.vendor.cpp(it)
        }
    }
}

All,

Just an update. I did some research, and found that the cross-compiler for roboRIO on both Windows and Linux was a GCC compiler.

I ran across this article:
Using the GNU Compiler Collection (GCC): Diagnostic Pragmas

So for our code, we now have:

// Ignore the warning that PIDController is deprecated
// TODO: WE WILL REMOVE ALL DEPRECATED CODE IN OFF-SEASON
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
  // Create a new PID contoller
  m_turnController = new PIDController(
    m_P_val, m_I_val, m_D_val, m_F_val,
    AHRS,
    this
  );
#pragma GCC diagnostic pop

This allows us to ignore individual warnings after we have determined if the warning is a real problem, or something that we are willing to accept the risk.

So now we have removed the code from above in build.gradle so that we do not ignore ALL deprecated warnings.

Just thought we would pass this along.

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