C++:枚举:错误:应使用标识符而不是"}"

C++: Enum: Error: Identifier expected instead of "}"

本文关键字:标识符 枚举 错误 C++      更新时间:2023-10-16

在 Solaris 11 x86 平台中从 openjdk 构建 jdk8u。收到警告:枚举中应使用标识符而不是"}"错误。通常,当我们在枚举末尾有逗号时,会抛出这种类型的错误。但在这种情况下,也没有额外的逗号。谁能指出问题出在哪里? 宏.hpp:

#ifndef INCLUDE_JFR
#define INCLUDE_JFR 1
#endif
#if INCLUDE_JFR
#define JFR_ONLY(code) code
#else
#define JFR_ONLY(code)
#endif

thread.hpp:

enum SuspendFlags {
// NOTE: avoid using the sign-bit as cc generates different test code
//       when the sign-bit is used, and sometimes incorrectly - see CR 6398077
_external_suspend       = 0x20000000U, // thread is asked to self suspend
_ext_suspended          = 0x40000000U, // thread has self-suspended
_deopt_suspend          = 0x10000000U, // thread needs to self suspend for deopt
_has_async_exception    = 0x00000001U, // there is a pending async exception
_critical_native_unlock = 0x00000002U, // Must call back to unlock JNI critical lock
JFR_ONLY(_trace_flag    = 0x00000004U)  // call jfr tracing
};

错误:

Compiling /export/home/preethi/openjdk8u/hotspot/src/share/vm/compiler/abstractCompiler.cpp
Compiling /export/home/preethi/openjdk8u/hotspot/src/share/vm/utilities/accessFlags.cpp
Compiling ../generated/adfiles/ad_x86_32.cpp
"/export/home/preethi/openjdk8u/hotspot/src/share/vm/runtime/thread.hpp", line 202: Warning: Identifier expected instead of "}".
1 Warning(s) detected.
gmake[6]: *** [/export/home/preethi/openjdk8u/hotspot/make/solaris/makefiles/rules.make:148: accessFlags.o] Error 2
gmake[6]: *** Waiting for unfinished jobs....
"/export/home/preethi/openjdk8u/hotspot/src/share/vm/runtime/thread.hpp", line 202: Warning: Identifier expected instead of "}".
1 Warning(s) detected.
gmake[6]: *** [/export/home/preethi/openjdk8u/hotspot/make/solaris/makefiles/rules.make:148: abstractCompiler.o] Error 2
"/export/home/preethi/openjdk8u/hotspot/src/share/vm/runtime/thread.hpp", line 202: Warning: Identifier expected instead of "}".
1 Warning(s) detected.
gmake[6]: *** [/export/home/preethi/openjdk8u/hotspot/make/solaris/makefiles/rules.make:148: ad_x86_32.o] Error 2
gmake[5]: *** [/export/home/preethi/openjdk8u/hotspot/make/solaris/makefiles/top.make:112: the_vm] Error 2
gmake[4]: *** [/export/home/preethi/openjdk8u/hotspot/make/solaris/Makefile:226: product] Error 2
gmake[3]: *** [Makefile:231: generic_build2] Error 2
gmake[2]: *** [Makefile:177: product] Error 2
gmake[1]: *** [HotspotWrapper.gmk:45: /export/home/preethi/openjdk8u/build/solaris-x86-normal-server-release/hotspot/_hotspot.timestamp] Error 2
gmake: *** [/export/home/preethi/openjdk8u//make/Main.gmk:110: hotspot-only] Error 2

规则制作:

%.o: %.cpp
@echo Compiling $<
$(QUIETLY) $(REMOVE_TARGET)
$(QUIETLY) $(if $(findstring $@, $(NONPIC_OBJ_FILES)), 
$(subst $(VM_PICFLAG), ,$(COMPILE.CXX)) $(DEPFLAGS) -o $@ $< $(COMPILE_DONE), 
$(COMPILE.CXX) $(DEPFLAGS) -o $@ $< $(COMPILE_DONE))

提前感谢!

我认为将枚举元素作为定义的条件的想法不容易维护。

如果你不能摆脱宏,你可以试试这个(谢谢@Mestkon(:

#define COMMA ,
enum SuspendFlags {
// NOTE: avoid using the sign-bit as cc generates different test code
//       when the sign-bit is used, and sometimes incorrectly - see CR 6398077
_external_suspend       = 0x20000000U, // thread is asked to self suspend
_ext_suspended          = 0x40000000U, // thread has self-suspended
_deopt_suspend          = 0x10000000U, // thread needs to self suspend for deopt
_has_async_exception    = 0x00000001U, // there is a pending async exception
_critical_native_unlock = 0x00000002U // (Removed end comma) Must call back to unlock JNI critical lock
JFR_ONLY(COMMA _trace_flag    = 0x00000004U)  // call jfr tracing
};

谢谢。我面临的问题是从openjdk构建jdk8u时。在配置中,我给出了--enable-jfr=yes,解决了我的问题。