After trying a few GCC experiments, there does not appear to be any way to work around “xor” keyword.

 

I recommend we update EDK II sources to not use c++ keywords to avoid this issue all together.

 

This may require changes that do not match names from industry standard specs.

 

Mike

 

From: Aaron Pop <aaronpop@microsoft.com>
Sent: Wednesday, May 24, 2023 1:08 PM
To: Kinney, Michael D <michael.d.kinney@intel.com>; devel@edk2.groups.io
Subject: RE: GoogleTest Compatibility with MdePkg's IndustyStandard header files

 

Hi Mike,

 

What you suggested does work for MSVC, but it is failing with GCC. It sems that GCC is very strict about operator names.

 

Relevant errors below:

 

error: "xor" cannot be used as a macro name as it is an operator in C++

#define xor       XOR

               ^~~

error: "xor" cannot be used as a macro name as it is an operator in C++

#undef xor

MdePkg/Include/IndustryStandard/Tpm20.h:1250:21: error: expected unqualified-id before ‘xor’ token

TPMI_ALG_HASH     xor;

                                    ^~~

MdePkg/Include/IndustryStandard/Tpm20.h:1323:20: error: expected unqualified-id before ‘xor’ token

TPMS_SCHEME_XOR  xor;

                                       ^~~

 

 

Aaron

 

From: Kinney, Michael D <michael.d.kinney@intel.com>
Sent: Wednesday, May 24, 2023 12:49 PM
To: Aaron Pop <aaronpop@microsoft.com>; devel@edk2.groups.io
Cc: Kinney, Michael D <michael.d.kinney@intel.com>
Subject: [EXTERNAL] RE: GoogleTest Compatibility with MdePkg's IndustyStandard header files

 

Hi Aaron,

 

Don’t know if this will completely resolve your issues, but if you add some preprocessor statements around the problematic includes in your unit test CPP file, you may be able to get it to build.

 

For example, I added the highlighted lines to MdePkg\Test\GoogleTest\Library\BaseSafeIntLib\TestBaseSafeIntLib.cpp and I can get that unit test to build.  Without the #define/#undef lines it fails in the way you describe.

 

#include <gtest/gtest.h>

extern "C" {

  #include <Base.h>

  #include <Library/SafeIntLib.h>

 

#define operator operator_

#define xor xor_

 

  #include <IndustryStandard/Tpm20.h>

  #include <IndustryStandard/Tpm12.h>

 

#undef operator

#undef xor

}

 

Mike

 

 

From: Aaron Pop <aaronpop@microsoft.com>
Sent: Monday, May 22, 2023 5:41 PM
To: devel@edk2.groups.io
Cc: Kinney, Michael D <michael.d.kinney@intel.com>
Subject: GoogleTest Compatibility with MdePkg's IndustyStandard header files

 

Google Test, and CPP, has more keywords  C uses.

 

Tpm12.h and Tpm20.h

have references to struct names that are `operator` and `xor`, both of which trigger build errors because they conflict with CPP’s keywords.

 

Operator triggered a build error in MSVC. Xor only triggered a build error under GCC, MSVC did not have a problem with it.

 

The work arounds suggested in the call, (using defines to get around the conflict) worked for operator, but did not work for xor with gcc. 

 

 

Tpm12.h:

TPM_PERMANENT_FLAGS

  BOOLEAN                           operator;

 

 

Tpm20.h:

TPMU_SCHEME_KEYEDHASH

  TPMS_SCHEME_XOR  xor;

TPMU_SYM_KEY_BITS

  TPMI_ALG_HASH     xor;

 

 

What is the suggested method of trying to make existing header files compatible with google test?

 

Thanks,

Aaron