Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect output for template code #365

Closed
IOBYTE opened this issue Dec 11, 2020 · 4 comments
Closed

Incorrect output for template code #365

IOBYTE opened this issue Dec 11, 2020 · 4 comments
Labels
bug Something isn't working

Comments

@IOBYTE
Copy link

IOBYTE commented Dec 11, 2020

This code:

template<long Len = 128, long BlockSize = 128, class T = wchar_t>
class String {
public:
  bool Format(const wchar_t FormatStr[], ...) { return true; }
};

void FTest() {
  double d{};

  String s;
  s.Format(L"%i", d);
}

produced this output:

template<long Len = 128, long BlockSize = 128, class T = wchar_t>
class S

/* First instantiated from: insights.cpp:10 */
#ifdef INSIGHTS_USE_TEMPLATE
template<>
String -> String<128, 128, wchar_t>;
#endif
tring {
public:
  bool Format(const wchar_t FormatStr[], ...) { return true; }
};

/* First instantiated from: insights.cpp:10 */
#ifdef INSIGHTS_USE_TEMPLATE
template<>
class String<128, 128, wchar_t>
{
  
  public: 
  inline bool Format(const wchar_t * FormatStr, ...)
  {
    return true;
  }
  
  // inline constexpr String() noexcept = default;
};

#endif


void FTest()
{
  double d = {};
  String<128, 128, wchar_t> s = String<128, 128, wchar_t>();
  s.Format(L"%i", d);
}

The first instantiation was inserted in the middle of the class name on line 2.

@andreasfertig
Copy link
Owner

Hello @IOBYTE,

thanks for catching and reporting this issue! It looks like the deduction guide is the trouble maker here. A patch is on its way.

Andreas

@andreasfertig andreasfertig added the bug Something isn't working label Dec 11, 2020
andreasfertig added a commit that referenced this issue Dec 11, 2020
Fixed #365: `CXXDeductionGuideDecl` appeared in the middle of a template
@IOBYTE
Copy link
Author

IOBYTE commented Dec 11, 2020

Thank you for the quick response.

I have a question about the output. Should it compile? The output on line 48 gives an error.

$ g++ -std=c++2a out.cpp
out.cpp:48:8: error: expected unqualified-id before ‘->’ token
   48 | String -> String<128, 128, wchar_t>;
      |        ^~
$ clang++ -std=c++20 out.cpp
out.cpp:48:8: error: cannot use arrow operator on a type
String -> String<128, 128, wchar_t>;
       ^
1 error generated.

@IOBYTE
Copy link
Author

IOBYTE commented Dec 11, 2020

I forgot to mention that I added this as the first line of the output:
#define INSIGHTS_USE_TEMPLATE

@andreasfertig
Copy link
Owner

Hello @IOBYTE,

it is not supposed to compile. Deduction guides are still an element I'm fighting with. However, I think I can make the one in this example work. Thanks for bringing it up.

Andreas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants