Skip to content

[BUG] Can't use #included declaration in requires clause #470

Open
@JohelEGP

Description

@JohelEGP

Title: Can't use #included declaration in requires clause.

Description:

A header include is treated like Cpp1 code and is emitted in phase 2.
A forward declaration in phase 1 can't make use of the header's symbols.

Minimal reproducer (https://cpp2.godbolt.org/z/fa4a7Kdo6):

main.h2:

v: const bool = true;

main.cpp2:

#include "main.h2"

t: <T> type requires v = { }

main: () = { }

Commands:

cppfront main.h2 -o _cppfront/main.h
cppfront main.cpp2 -o _cppfront/main-3.cpp
clang++17 -std=c++2b -stdlib=libc++ -lc++abi -pedantic-errors -Wall -Wextra -Wconversion -I . _cppfront/main-3.cpp

Expected result:

A well-formed program.

Actual result and error:

Cpp2 lowered to Cpp1.

_cppfront/main.h:

//=== Cpp2 type declarations ====================================================


#include "cpp2util.h"



//=== Cpp2 type definitions and function declarations ===========================

extern bool const v;

//=== Cpp2 function definitions =================================================

bool const v {true}; 

_cppfront/main-3.cpp:

//=== Cpp2 type declarations ====================================================


#include "cpp2util.h"


template<typename T> requires( v )

class t;

//=== Cpp2 type definitions and function declarations ===========================

#include "main.h"

template<typename T> requires( v )

class t {
      public: t() = default;
      public: t(t const&) = delete; /* No 'that' constructor, suppress copy */
      public: auto operator=(t const&) -> void = delete;

};

auto main() -> int;


//=== Cpp2 function definitions =================================================


auto main() -> int{}

Output.

build/_cppfront/main-3.cpp:6:32: error: 'v' was not declared in this scope
    6 | template<typename T> requires( v )
      |                                ^

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions