godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.49k stars 21.07k forks source link

ERROR_CODE constant in Converter3To4 class implementation is out of scope/undefined when building without the Regex module #62206

Closed georgjz closed 2 years ago

georgjz commented 2 years ago

Godot version

01efb938424c7678f5a834e25244d4ed741c563a

System information

Windows 10, MSVC 14.3

Issue description

The constant const int ERROR_CODE = 77; at line 42 of the file editor\project_converter_3_to_4.cpp is only defined in one branch of the overall conditional-compilation expression:

#ifdef MODULE_REGEX_ENABLED

// ...

const int ERROR_CODE = 77;

// ...

#else // No regex.

int ProjectConverter3To4::convert() {
    ERR_FAIL_V_MSG(ERROR_CODE, "Can't run converter for Godot 3.x projects as RegEx module is disabled.");
}

int ProjectConverter3To4::validate_conversion() {
    ERR_FAIL_V_MSG(ERROR_CODE, "Can't validate conversion for Godot 3.x projects as RegEx module is disabled.");
}

#endif // MODULE_REGEX_ENABLED

The functions ProjectConverter3To4::convert() and ProjectConverter3To4::validation_conversion() cannot be compiled as ERROR_CODE is not in scope for them.

This results in the follwing error message:

Configuring for Windows: target=release_debug, bits=64
Found MSVC version 14.3, arch amd64, bits=64
Checking for C header file mntent.h... (cached) no
scons: done reading SConscript files.
scons: Building targets ...
[ 77%] cl /Foeditor\project_converter_3_to_4.windows.opt.tools.x64.4.0.obj /c editor\project_converter_3_to_4.cpp /TP /std:c++17 /nologo /O2 /Zi /FS /MT /Gd /GR /utf-8 /W3 /wd4267 /wd4244 /wd4305 /wd4018 /wd4800 /EHsc /DDEBUG_ENABLED /DNO_EDITOR_SPLASH /DDISABLE_DEPRECATED /DWINDOWS_ENABLED /DWASAPI_ENABLED /DWINMIDI_ENABLED /DTYPED_METHOD_BIND /DWIN32 /DMSVC /DWINVER=0x0601 /D_WIN32_WINNT=0x0601 /DNOMINMAX /D_WIN64 /DVULKAN_ENABLED /DGLES3_ENABLED /DTOOLS_ENABLED /DMINIZIP_ENABLED /DZSTD_STATIC_LINKING_ONLY /DUSE_VOLK /DVK_USE_PLATFORM_WIN32_KHR /DGLAD_ENABLED /DGLES_OVER_GL /Ithirdparty\freetype\include /Ithirdparty\libpng /Ithirdparty\glad /Ithirdparty\volk /Ithirdparty\vulkan /Ithirdparty\vulkan\include /Ithirdparty\zstd /Ithirdparty\zlib /Iplatform\windows /I.
project_converter_3_to_4.cpp
editor\project_converter_3_to_4.cpp(3804): error C2065: 'ERROR_CODE': undeclared identifier
editor\project_converter_3_to_4.cpp(3808): error C2065: 'ERROR_CODE': undeclared identifier
scons: *** [editor\project_converter_3_to_4.windows.opt.tools.x64.4.0.obj] Error 2
scons: building terminated because of errors.

Steps to reproduce

Clone repository and build on indicated commit with the following custom script:

# custom.py

import version

platform    = "windows"
tools       = "yes"
tests       = "yes"
target      = "release_debug"
arch        = "x64"
bits        = "64"
optimize    = "speed"  # default
# deprecated: Enable deprecated features (yes|no)
deprecated  = "no"
verbose     = "yes"

module_arkit_enabled = "no"
module_bmp_enabled = "no"
module_bullet_enabled = "no"
module_camera_enabled = "no"
module_csg_enabled = "no"
module_dds_enabled = "no"
module_enet_enabled = "no"
module_etc_enabled = "no"
module_gdnative_enabled = "no"
module_gridmap_enabled = "no"
module_hdr_enabled = "no"
module_jsonrpc_enabled = "no"
module_mbedtls_enabled = "no"
module_mobile_vr_enabled = "no"
module_opensimplex_enabled = "no"
module_opus_enabled = "no"
module_pvr_enabled = "no"
module_recast_enabled = "no"
module_regex_enabled = "no"
module_squish_enabled = "no"
module_tga_enabled = "no"
module_theora_enabled = "no"
module_tinyexr_enabled = "no"
module_upnp_enabled = "no"
module_vhacd_enabled = "no"
module_vorbis_enabled = "no"
module_webm_enabled = "no"
module_webrtc_enabled = "no"
module_websocket_enabled = "no"
module_xatlas_unwrap_enabled = "no"

# Override options specific for Godot 3.x and 4.x versions.
if version.major == 3:
    extra_suffix = "3.4"
    pass
elif version.major == 4:
    extra_suffix = "4.0"
    pass

Minimal reproduction project

No response

georgjz commented 2 years ago

I'd propose to use a if constexpr for both functions in question:

int ProjectConverter3To4::convert() {
        if constexpr (!MODULE_REGEX_ENABLED) {
            ERR_FAIL_V_MSG(ERROR_CODE, "Can't run converter for Godot 3.x projects as RegEx module is disabled.");
        }
        else {
        // rest of code
       }
}

Or trivially, move the definition of ERROR_CODE before #ifdef MODULE_REGEX_ENABLED. I'd be happy to commit a PR solving this.

akien-mga commented 2 years ago

The whole class relies on RegEx, so your if constexpr solution would require adding a lot of guards in other functions.

Moving the definition of ERROR_CODE is the simplest and thus best solution.