Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

Initialisation of for-loop variable using string literal

Koschier__Dan
Beginner
705 Views

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
705 Views

What is VS version?

0 Kudos
Koschier__Dan
Beginner
705 Views

Hi Viet,

I’m using VS2017.

Best, Dan

0 Kudos
Koschier__Dan
Beginner
705 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?

0 Kudos
Viet_H_Intel
Moderator
705 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>

0 Kudos
Koschier__Dan
Beginner
705 Views

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

0 Kudos
Viet_H_Intel
Moderator
705 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;
}

0 Kudos
Koschier__Dan
Beginner
705 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?

0 Kudos
Viet_H_Intel
Moderator
705 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>

0 Kudos
Koschier__Dan
Beginner
705 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.

0 Kudos
Reply