Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Koschier__Dan
Beginner
112 Views

Initialisation of for-loop variable using string literal

Hi,

I've recently encountered a compiler error using the Intel compiler using the following code:

inline unsigned long long operator""_abc(const unsigned long long value)
{
    return value;
}

int main()
{
    auto a = 0_abc;
    for (; a < 2_abc; ++a)
    {
    }

    for (auto b = 0_abc; b < 2_abc; ++b)
    {
    }

    return 0;
}

The compiler error I get is 

1>C:\Users\dkoschier\Dev\StringLiteral\StringLiteral\main.cpp(14): error : user-defined literal operator not found
1>      for (auto b = 0_abc; b < 2_abc; ++b)
 

The first for-loop happily compiles while the initialisation in the second one doesn't. I genuinely believe this is a bug in the compiler.

Does anyone know of a way to fix this problem? 

EDIT: Occured using Intel® C++ Compiler 18.0 in Windows 10

0 Kudos
9 Replies
Viet_H_Intel
Moderator
112 Views

What is VS version?

Koschier__Dan
Beginner
112 Views

Hi Viet,

I’m using VS2017.

Best, Dan

Koschier__Dan
Beginner
112 Views

I still haven't found a solution for this problem. Does maybe anyone know if this problem is fixed in the newest version of the compiler?

Viet_H_Intel
Moderator
112 Views

Are there any options that you used? I couldn't even compile your test program with cl.

C:\Temp>cl t.c /c
Microsoft (R) C/C++ Optimizing Compiler Version 19.23.28105.4 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

t.c
t.c(1): error C2143: syntax error: missing '{' before 'string'
t.c(1): error C2059: syntax error: 'string'
t.c(8): error C2059: syntax error: 'bad suffix on number'
t.c(9): error C2059: syntax error: 'bad suffix on number'
t.c(13): error C2059: syntax error: 'bad suffix on number'

C:\Temp>

Koschier__Dan
Beginner
112 Views

No, I haven't. Only, at least C++11 support should be enabled.

Viet_H_Intel
Moderator
112 Views


C:\Temp>cl t.c /c /std:c++14
Microsoft (R) C/C++ Optimizing Compiler Version 19.23.28105.4 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

t.c
t.c(1): error C2143: syntax error: missing '{' before 'string'
t.c(1): error C2059: syntax error: 'string'
t.c(8): error C2059: syntax error: 'bad suffix on number'
t.c(9): error C2059: syntax error: 'bad suffix on number'
t.c(13): error C2059: syntax error: 'bad suffix on number'

C:\Temp>notepad t.c

inline unsigned long long operator""_abc(const unsigned long long value)
{
    return value;
}

int main()
{
    auto a = 0_abc;
    for (; a < 2_abc; ++a)
    {
    }

    for (auto b = 0_abc; b < 2_abc; ++b)
    {
    }

    return 0;
}

Koschier__Dan
Beginner
112 Views

Hi, Thank you for trying this out.

I suspect it doesn't compile for you, because you have named the source file "t.c". I assume that the compiler then uses the C-compiler instead of the C++ compiler. Could you try renaming the file to "t.cpp" and check again, please?

Viet_H_Intel
Moderator
112 Views

Compiled OK with ICL19.1

C:\Temp>icl t.cpp  /std:c++14
Intel(R) C++ Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 19.1.0.166 Build 20191121
Copyright (C) 1985-2019 Intel Corporation.  All rights reserved.

t.cpp
Microsoft (R) Incremental Linker Version 14.23.28105.4
Copyright (C) Microsoft Corporation.  All rights reserved.

-out:t.exe
t.obj

C:\Temp>

Koschier__Dan
Beginner
112 Views

Great. Thank you for testing. In that case I simply need to convince some people to switch to a newer version of the Intel compiler.

Reply