Compiler behavior and "register storage class specifier is deprecated"

2.2k views Asked by At

I'm testing some C++ code with -std=c++11. I noticed a warning I had not seen before:

'register' storage class specifier is deprecated

What does the standard say about this (other than its deprecated)?

Is it implementation defined?

Will compilers take it as a hint and try to put the value in a register?

Will this eventually lead to a compile failure?

Perhaps something else?

2

There are 2 answers

0
ecatmur On BEST ANSWER

C++11, [dcl.stc]:

3 - A register specifier is a hint to the implementation that the variable so declared will be heavily used. [ Note: The hint can be ignored and in most implementations it will be ignored if the address of the variable is taken. This use is deprecated (see D.2). — end note ]

There is a proposal to remove the register keyword as a storage specifier, while reserving it as a keyword: Remove Deprecated Use of the register Keyword (n4340). This may or may not be implemented in C++1z (tentative C++17); it would pose challenges for compatibility with C, where register still has semantic effect (a C register variable or parameter cannot have its address taken or be subject to array-to-pointer decay).

1
user207421 On

Is it implementation defined?

It always was.

Will compilers take it as a hint and try to put the value in a register?

It's implementation-defined.

Will this eventually lead to a compile failure?

No.

EDIT Perhaps I misunderstood the question about the eventual compile failure. I took it to mean an eventual failure in the current compilation. If the question is about the future of the register keyword, anything is possible: I don't care to fortune-tell.