Skip to content

[microsoft] sema for __noop is fairly wrong #14453

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

Open
nico opened this issue Oct 14, 2012 · 4 comments
Open

[microsoft] sema for __noop is fairly wrong #14453

nico opened this issue Oct 14, 2012 · 4 comments
Labels
bugzilla Issues migrated from bugzilla c++ clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party diverges-from:msvc Does the clang frontend diverge from msvc on this issue extension:microsoft

Comments

@nico
Copy link
Contributor

nico commented Oct 14, 2012

Bugzilla Link 14081
Version unspecified
OS All
Blocks #14079
Attachments as UnaryExprOrTypeTrait, As builtin with special handling
CC @DougGregor,@zmodem,@tritao,@rnk

Extended Description

Eli pointed out in an email that

template<typename T> static void f() { T x = 10; }
void g() { __noop(f<void>()); }

is an interesting case for __noop that compiles with cl but not with clang.

__noop has a few other interesting cases too:

  • int __noop = 4 is a syntax error in cl; __noop is a keyword

  • int a = __noop(42, 56); assigns 0 to a, but so does int a = __noop;. All of the following are valid, all but the first assign 0 to a:

  __noop;
  a = __noop;
  a = __noop();
  a = (__noop)();
  a = (__noop);
  a = (__noop());
  a = ((__noop)());
  a = ((__noop))();
  • __noop is converted to pointers like a 0 literal:
  int (*f2)() = __noop;  // works, but just assings 0 to f2
  • ...but it's not a constant expression:
  int arr[__noop() + 1];  // errors out
@nico
Copy link
Contributor Author

nico commented Jul 9, 2014

More fun:

#include <typeinfo>
#include <iostream>

#include <stdio.h>
using namespace std;

template<typename T> static void f() { T x = 10 asdf asdf asd asdf }
void g() { __noop(f<void>()); }

class A {
public:
 void f();
};

int main() {
  //&__noop;
  int a[__noop(4 asdfasdf^*^&$^)(4, 5) + 1];
  decltype(__noop) ac;
  ac = 4;

  void (A::*foo)() = __noop;
 
  cout << typeid(__noop).name() << endl;
}

(Note that it's a constexpr in msvs2013)

@rnk
Copy link
Collaborator

rnk commented Aug 11, 2014

Hm, unfortunately I didn't notice this bug, so I rediscovered all these wonderful features a few months ago. I added support for paren-less __noop in r212860, but we should probably promote this to a first class Expr node if we want to get it 100% right.

@llvmbot
Copy link
Member

llvmbot commented Jan 20, 2015

I’m working on this issue to make __noop a first class Expr.

--
Ilia Filippov
Software Engineer
Intel Compiler Team
Intel Corp.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 3, 2021
@llvmbot llvmbot added the confirmed Verified by a second party label Jan 26, 2022
@Endilll Endilll changed the title [microsoft] sema for __noop is fairly wrong [microsoft] sema for __noop is fairly wrong Jul 28, 2024
@AaronBallman AaronBallman added diverges-from:msvc Does the clang frontend diverge from msvc on this issue clang:frontend Language frontend issues, e.g. anything involving "Sema" and removed clang:to-be-triaged Should not be used for new issues labels Apr 16, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 16, 2025

@llvm/issue-subscribers-clang-frontend

Author: Nico Weber (nico)

| | | | --- | --- | | Bugzilla Link | [14081](https://llvm.org/bz14081) | | Version | unspecified | | OS | All | | Blocks | llvm/llvm-project#14079 | | Attachments | [as UnaryExprOrTypeTrait](https://user-images.githubusercontent.com/3487/143746161-5d61078b-04e5-4314-ae07-230774ebc69c.gz), [As builtin with special handling](https://user-images.githubusercontent.com/3487/143746162-fd25f418-05d7-4b31-bae3-b29011473dc6.gz) | | CC | @DougGregor,@zmodem,@tritao,@rnk |

Extended Description

Eli pointed out in an email that

template&lt;typename T&gt; static void f() { T x = 10; }
void g() { __noop(f&lt;void&gt;()); }

is an interesting case for __noop that compiles with cl but not with clang.

__noop has a few other interesting cases too:

  • int __noop = 4 is a syntax error in cl; __noop is a keyword

  • int a = __noop(42, 56); assigns 0 to a, but so does int a = __noop;. All of the following are valid, all but the first assign 0 to a:

  __noop;
  a = __noop;
  a = __noop();
  a = (__noop)();
  a = (__noop);
  a = (__noop());
  a = ((__noop)());
  a = ((__noop))();
  • __noop is converted to pointers like a 0 literal:
  int (*f2)() = __noop;  // works, but just assings 0 to f2
  • ...but it's not a constant expression:
  int arr[__noop() + 1];  // errors out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla c++ clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party diverges-from:msvc Does the clang frontend diverge from msvc on this issue extension:microsoft
Projects
None yet
Development

No branches or pull requests

5 participants