HaxeFoundation / HaxeFoundation/haxe

haxe cpp build fails with "expected unqualified-id ..." message

Open
#8,126 0 comments 0 reactions 0 assignees View on GitHub
platform-cpp
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

UPDATE:
As I was reproducing this issue on OSX I realized that `M_PI_2` is actually `#define` from `math.h` and that is why the build is failing. If I change M_PI_2 to i.e. M_PI_2a it builds fine, I just get a lot of warnings:

warning: dynamic exception specifications are deprecated in C++11 [-Wdeprecated]

Maybe there is a way to handle these kind of edge cases, maybe not, and I'm not even sure if this should be logged as a bug or maybe added to wiki or something.

In any case, I'm logging this since it might help someone else who has similar issue in the future. Please close the issue if it is not a bug. Thanks!

Original issue text:

I'm not quite sure what is the issue here, maybe it's not the static var like it says in title.

I've found similar issue [#2221](https://github.com/HaxeFoundation/haxe/issues/2221) but I have no idea if it is related or not.

Linux build fails with `include/Main.h:49:16: error: expected unqualified-id before numeric constant`. To reproduce create Main.hx with following content:

package;

class Main {

public static var M_PI_2 : Float = Math.PI* 2.0;

public static function main () {
trace('M_PI_2 = ' + M_PI_2);
}
}

then build:

$ haxe -cp . -main Main -cpp build

which fails with lengthy error(s):

haxelib run hxcpp Build.xml haxe -Dhaxe3="1" -Dhaxe_ver="4.000" -Dhxcpp_api_level="400" -Dsource-header="Generated by Haxe 4.0.0-preview.5" -Dstatic="1" -Dutf16="1" -I"./" -I"" -I"/usr/local/share/haxe/std/cpp/_std/" -I"/usr/local/share/haxe/std/"
Creating /home/user/Development/test1/build/obj/linux64/__pch/haxe/hxcpp.h.gch...

Compiling group: haxe
g++ -Iinclude -c -fvisibility=hidden -O2 -fpic -fPIC -Wno-overflow -DHX_LINUX -DHXCPP_M64 -DHXCPP_VISIT_ALLOCS(haxe) -DHXCPP_API_LEVEL=400(haxe) -m64 -DHXCPP_M64 -I/home/user/.haxelibrepo/hxcpp/4,0,8/include ... tags=[haxe,static]
- src/Main.cpp
Error: In file included from /usr/include/c++/7/cmath:45:0,
from /usr/include/c++/7/math.h:36,
from /home/user/.haxelibrepo/hxcpp/4,0,8/include/hxMath.h:8,
from ./src/Main.cpp:6:
include/Main.h:54:16: error: expected unqualified-id before numeric constant
static Float M_PI_2;
^
./src/Main.cpp:35:17: error: expected unqualified-id before numeric constant
Float Main_obj::M_PI_2;
^
./src/Main.cpp: In static member function ‘static void Main_obj::main()’:
./src/Main.cpp:39:77: error: expected unqualified-id before numeric constant
HXDLIN( 6) ::haxe::Log_obj::trace((HX_("hola",3c,c9,12,45) + ::Main_obj::M_PI_2),hx::SourceInfo(HX_("./Main.hx",e4,2d,22,70),6,HX_("Main",59,64,2f,33),HX_("main",39,38,56,48)));
^
./src/Main.cpp:39:77: error: expected ‘)’ before numeric constant
./src/Main.cpp: In static member function ‘static bool Main_obj::__SetStatic(const String&, Dynamic&, hx::PropertyAccess)’:
./src/Main.cpp:66:69: error: lvalue required as left operand of assignment
if (HX_FIELD_EQ(inName,"M_PI_2") ) { M_PI_2=ioValue.Cast< Float >(); return true; }
^
In file included from /home/user/.haxelibrepo/hxcpp/4,0,8/include/hxcpp.h:342:0:
./src/Main.cpp: In function ‘void Main_obj_sMarkStatics(hx::MarkContext*)’:
./src/Main.cpp:80:32: error: expected unqualified-id before numeric constant
HX_MARK_MEMBER_NAME(Main_obj::M_PI_2,"M_PI_2");
^
/home/user/.haxelibrepo/hxcpp/4,0,8/include/hx/GC.h:539:52: note: in definition of macro ‘HX_MARK_MEMBER_NAME’
#define HX_MARK_MEMBER_NAME(x,name) hx::MarkMember(x, __inCtx )
^
./src/Main.cpp: In function ‘void Main_obj_sVisitStatics(hx::VisitContext*)’:
./src/Main.cpp:85:33: error: expected unqualified-id before numeric constant
HX_VISIT_MEMBER_NAME(Main_obj::M_PI_2,"M_PI_2");
^
/home/user/.haxelibrepo/hxcpp/4,0,8/include/hx/GC.h:560:54: note: in definition of macro ‘HX_VISIT_MEMBER_NAME’
#define HX_VISIT_MEMBER_NAME(x,name) hx::VisitMember(x, __inCtx )
^
./src/Main.cpp: In static member function ‘static void Main_obj::__boot()’:
./src/Main.cpp:129:54: error: lvalue required as left operand of assignment
HXDLIN( 4) M_PI_2 = (::Math_obj::PI * ((Float)2.0));
^
Error: Build failed

Running `haxe -cp . -main Main -neko Main.n` works as expected.

Details:

$ haxe
Haxe Compiler 4.0.0-preview.5 - (C)2005-2018 Haxe Foundation

$ gcc --version
gcc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0

Same build also fails on OSX:

Error: In file included from ./src/Main.cpp:9:
include/Main.h:49:16: error: expected member name or ';' after declaration specifiers
static Float M_PI_2;
~~~~~~~~~~~~ ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include/math.h:704:21: note: expanded from macro 'M_PI_2'
#define M_PI_2 1.57079632679489661923132169163975144 /* pi/2 */
^
./src/Main.cpp:30:79: error: expected unqualified-id
HXLINE( 11) ::haxe::Log_obj::trace((HX_("M_PI_2",9e,ad,a4,b1) + ::Main_obj::M_PI_2),hx::SourceInfo(HX_("Source/Main.hx",b1,67,fd,ea),11,HX_("Main",59,64,2f,33),HX_("new",60,d0,53,00)));
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include/math.h:704:21: note: expanded from macro 'M_PI_2'
#define M_PI_2 1.57079632679489661923132169163975144 /* pi/2 */
^
./src/Main.cpp:56:17: error: expected unqualified-id
Float Main_obj::M_PI_2;
^
./src/Main.cpp:89:46: error: expression is not assignable
if (HX_FIELD_EQ(inName,"M_PI_2") ) { M_PI_2=ioValue.Cast< Float >(); return true; }
~~~~~~^
./src/Main.cpp:103:32: error: expected unqualified-id
HX_MARK_MEMBER_NAME(Main_obj::M_PI_2,"M_PI_2");
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include/math.h:704:21: note: expanded from macro 'M_PI_2'
#define M_PI_2 1.57079632679489661923132169163975144 /* pi/2 */
^
./src/Main.cpp:108:33: error: expected unqualified-id
HX_VISIT_MEMBER_NAME(Main_obj::M_PI_2,"M_PI_2");
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include/math.h:704:21: note: expanded from macro 'M_PI_2'
#define M_PI_2 1.57079632679489661923132169163975144 /* pi/2 */
^
./src/Main.cpp:151:22: error: expression is not assignable
HXDLIN( 7) M_PI_2 = (::Math_obj::PI * ((Float)2.0));
~~~~~~ ^
7 errors generated.

Details:

$ haxe
Haxe Compiler 4.0.0-preview.5+7eb789f - (C)2005-2018 Haxe Foundation

$ clang++ --version
Apple LLVM version 9.0.0 (clang-900.0.37)
Target: x86_64-apple-darwin16.7.0

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.