Skip to content

custom ostream formatter vs namespace vs clang #1550

@anordal

Description

@anordal

I have basically #952 (comment) with a namespace:

#include <fmt/ostream.h>
#include <iostream>

namespace something{ struct Custom {}; }

std::ostream& operator<<(std::ostream& os, const something::Custom&)
{
	return os << "Ok";
}

int main()
{
	// Compiles with Gcc and Clang
	std::cout << something::Custom() << '\n';

	// Compiles with Gcc, but not Clang
	fmt::print("{}\n", something::Custom());
}

I don't know if this is a compiler bug, but it seems that clang + libfmt = operator<< not found.

The absurd thing is that it compiles (with both compilers, also the non-libfmt example) if I move operator<< into the namespace. That is not supposed to compile (if my understanding of argument dependent lookup is correct) – I learned this from the exact opposite experience.

Libfmt tested:

  • libfmt 6.1.2-1.2 (OpenSuse package)
  • latest git (dc22360)

Compilers tested:

  • g++ 9.2.1
  • g++ 7.4.1
  • clang++ 9.0.0
  • clang++ 6.0.1

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