Skip to content

A constexpr function definiton in a header is ignored if declaration visible in different file #1263

@davmac314

Description

@davmac314

Describe the bug
A constexpr function definiton in a header is ignored if a declaration of the same function (without body) is visible in primary source file.

To Reproduce
Steps to reproduce the behavior:

In foo.h:

constexpr int getConstVal() { return 1; }

In foo.cc:

#include <foo.h>

constexpr int getConstVal();

constexpr int v = getConstVal();

template <int V> struct Foo;
template <> struct Foo<1> {
    constexpr static int val = 55;
};

int x = Foo<v>::val;

The final line in foo.cc will be highlighted as an error ("symbol 'val' could not be resolved"). This is due to a failure to correctly resolve v as the constant 1 via the call to getConstVal() (which returns 1).

If the definition is moved from the header to the top of foo.cc (or anywhere else in foo.cc) the error goes away.

Expected behavior
No error should be marked. Whether the definition is in a header or in the main source file should make no difference.

Screenshots
See source samples above.

Version Information (please complete the following information):

  • OS and OS Version/extra details: Linux but N/A
  • Eclipse Version: 2025-06 (4.36)
  • CDT Version: 12.1.0.202506041907

Additional context
N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions