https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104514

            Bug ID: 104514
           Summary: add feature to create a pointer to a fixed address as
                    constexpr
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: goswin-v-b at web dot de
  Target Milestone: ---

In the embedded and micro controller world memory mapped registers are very
common. They can be declared as external object and fudged in using linker
scripts, which prevents a lot of optimizations. Or they can be declared as
pointers, in the most reduced form like this:

    int *p = (int*)0x12345678;

My problem now is that this isn't a constexpr and can't be used in any
constexpr code:

    foo.cc:1:20: error: ‘reinterpret_cast’ from integer to pointer
        1 | constexpr int *p = (int*)0x12345678;
          |                    ^~~~~~~~~~~~~~~~

While this is the right thing in general there should be a way to allow this
special case. A way to tell the compiler that an object exists at a fixed
address and still be a constexpr.

Reply via email to